I'm developing an OOB Silverlight application and using the COM Toolkit (http://silverlightcom.codeplex.com), the language is Visual Basic (VB). With this pack, I can connect my app with my Microsoft SQL Server database using ADO.NET. It works, but when I try to insert a null value to a parameter it throws an exception: 0x800A0BB9 (http://prntscr.com/43zwyr).
My code is (I will post the most simple stretch):
Private Const SqlCreateJob As String = "insert into Cargos(Nome_carg, Desc_carg) values(?, ?)"
Public Shared Sub CreateJob(ByVal j As Job)
Dim conn As AdoConnection = DbUtil.GetConn
Dim cmd As AdoCommand = conn.CreateCommand
cmd.CommandText = SqlCreateJob
cmd.Parameters.AddWithValue("Nome_carg", j.Name)
cmd.Parameters.AddWithValue("Desc_carg", j.Desc)
For Each p As AdoParameter In cmd.Parameters
If p.Value = Nothing Then
p.Value = DBNull.Value
End If
Next
cmd.ExecuteNonQuery()
conn.Close()
End Sub
And the class Job:
Public Class Job
Property Code() As Integer
Property Name() As String
Property Desc() As String
End Class
The value Desc, from Job, can be null. And if I put
cmd.Parameters.AddWithValue("Desc_carg", DBNull.Value) it still doesn't work. What can I do? (When the Desc is not null the command works)
The Exception.ToString is here:
System.Runtime.InteropServices.COMException (0x800A0BB9): Exception from HRESULT: 0x800A0BB9 ---> MS.Internal.ComAutomation.ComAutomationObjectException: The arguments are incorrect, are out of acceptable range, or are in conflict.(Source=ADODB.Parameter) (HelpFile=C:\WINDOWS\HELP\ADO270.CHM#1240641) em MS.Internal.ComAutomation.ComAutomationNative.CheckInvokeHResult(UInt32 hr, String memberName, String exceptionSource, String exceptionDescription, String exceptionHelpFile, UInt32 exceptionHelpContext) em MS.Internal.ComAutomation.ComAutomationNative.Invoke(Boolean tryInvoke, String memberName, ComAutomationInvokeType invokeType, ComAutomationInteropValue[] rgParams, IntPtr nativePeer, ComAutomationInteropValue& returnValue) em MS.Internal.ComAutomation.ComAutomationObject.InvokeImpl(Boolean tryInvoke, String name, ComAutomationInvokeType invokeType, Object& returnValue, Object[] args) em MS.Internal.ComAutomation.ComAutomationObject.Invoke(String name, ComAutomationInvokeType invokeType, Object[] args) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProvider.TrySetMember(SetMemberBinder binder, Object value) em System.Runtime.InteropServices.Automation.AutomationMetaObjectProviderBase.<.cctor>b__3(Object obj, SetMemberBinder binder, Object value) em CallSite.Target(Closure , CallSite , Object , Int32 ) em System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) em CallSite.Target(Closure , CallSite , Object , Int32 ) em ComToolkit.Data.AdoParameter.set_Type(DbType value) em ComToolkit.Data.AdoParameter..ctor(Object adoParameter, String name, Object value) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) em CallSite.Target(Closure , CallSite , Type , Object , String , Object ) em ComToolkit.Data.AdoCommand.CreateParameter(String name, Object value) em ComToolkit.Data.AdoParameterCollection.AddWithValue(String name, Object value) em Corporativo.Dao.CargoDao.AddParameters(AdoCommand cmd, Cargo c) em Corporativo.Dao.CargoDao.CriarCargo(Cargo c) em Corporativo.UCCadCargos.Create()
And the .Message:
Exception from HRESULT: 0x800A0BB9
You should not be using AddWithValue if the value is, or van be, NULL. AddWithValue infers the data type of the parameter from the value but, if the value is NULL, a type cannot be inferred. You should be using Add in such cases, specifying the data type explicitly and setting the Value property.
Related
I am working on a VB app that uses a SQL Server database.
The issue I am having is that users are no longer able to login from the website.
However, when I run locally against the same database, it works just fine.
I have gone through the logs and determined its the SqlConnection() object that is throwing the
Object reference not set to an instance of an object.
error once oCn.Open() is called.
Public Function ValidLogin(ByVal EmpNum As String, ByVal Password As String, ByRef ErrMsg As String) As Boolean
Dim oCn As New SqlConnection(GetAPP2Password())
Dim oDr As SqlDataReader = Nothing
Dim oCmd As SqlCommand = Nothing
Dim sResponse As String = ""
ErrMsg = ""
Try
oCn.Open()
// do whatever else i need to do
Finally
oDr.Close()
oCn.Close()
oCmd.Dispose()
End Try
Return sResponse = "VALID"
Public Function GetAPP2Password() As String
Return sAPP2Password
End Function
this is the function that sets "sAPP2Password"
Public Function LoadPasswordString(ByVal databaseName As String) As String
'Reads a given setting from the <appSettings> section in the Web.config file.
'The setting key is prefixed with the current HostName to enable us to have one
'Web.config file that works for DVLP,ACPT and PROD with no mods required when
'moving between environments.
Dim strReturn As String = ""
Dim cc As New CECCoupler
strReturn = cc.getSecret(databaseName)
If InStr(strReturn, "Error:") Then ' check strReturn for ERROR
LogEvent("Globals.vb", "System", "Localhost", strReturn)
End If
Return strReturn
End Function
I am trying to figure out what the issue is on the application so I can get users back to logging in to the site.
below is the logged error from the application
Object reference not set to an instance of an object. at APP.APP2DataAccess.ValidLogin(String EmpNum, String Password, String& ErrMsg)
at APP.Login.cmdLogin_Click(Object sender, EventArgs e)
I have encountered a error in VB.NET when I want to get the owner of a file.
This is my code.
Imports System.Security.AccessControl
Imports System.Security.Principal
Imports System.IO
Dim fi As FileInfo = New FileInfo("X:\Temp\aa.txt")
Dim fs As FileSecurity = fi.GetAccessControl
Dim myuser As IdentityReference = fs.GetOwner(GetType(NTAccount))
Dim username = myuser.Value.ToString
and I got error:
System.Security.Principal.IdentityNotMappedException was caught
HResult=-2146233087
Message=Unable to translate some or all of the recognition references。
Source=mscorlib
StackTrace:
System.Security.Principal.SecurityIdentifier.Translate(IdentityReferenceCollection sourceSids, Type targetType, Boolean forceSuccess)
in System.Security.Principal.SecurityIdentifier.Translate(Type targetType)
in System.Security.AccessControl.ObjectSecurity.GetOwner(Type targetType)
in Ts2.From1.Button1_Click(Object sender, EventArgs e) 於 D:\Ts3\Ts1\Form1.vb: row 292
InnerException:
ypu can easily get the owner of a file or folder using this ...
Public Function GetFileOwner(ByVal fileName As String) As String
Try
Dim fi As New FileInfo(fileName)
Dim fs As System.Security.AccessControl.FileSecurity = fi.GetAccessControl
Dim owner As System.Security.Principal.NTAccount = CType(fs.GetOwner(GetType(System.Security.Principal.NTAccount)), System.Security.Principal.NTAccount)
Return owner.ToString
Catch ex As Exception
Return ""
End Try
End Function
Public Function GetDirOwner(ByVal fileName As String) As String
Try
Dim di As New DirectoryInfo(fileName)
Dim ds As System.Security.AccessControl.DirectorySecurity = di.GetAccessControl
Dim owner As System.Security.Principal.NTAccount = CType(ds.GetOwner(GetType(System.Security.Principal.NTAccount)), System.Security.Principal.NTAccount)
Return owner.ToString
Catch ex As Exception
Return ""
End Try
End Function
I've created a Script Task in my SSIS 2012 package that needs to grab files from a FTP server and store them on the local server's hard drive. The code I've written in the script task s as follows:
Public Sub Main()
'
' Add your code here
'
Const localFile As String = "C:\InboundOrders\*.*"
Const remoteFile As String = "/remote/folder/filename.pgp"
Const host As String = "ftp://ftp1.commerceub.com"
Const user As String = "ourusername"
Const pw As String = "ourpassword"
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI),
FtpWebRequest)
ftp.Credentials = New System.Net.NetworkCredential(user, pw)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Using response As System.Net.FtpWebResponse = CType(ftp.GetResponse,
System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
Dts.TaskResult = ScriptResults.Success
End Sub
When I run the package, I receive an error stating:
DTS Script Task has encountered an exception in user code.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr,
Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder
binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers,
CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder,
Object target, Object[] args, CultureInfo culture)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
What should I do to remedy the above error? Thanks for your help and guidance.
UPDATE: I specified a file that is actually on the FTP server in my code. I receive the same error. Is there a different approach I should take?
I become an errorcode 1001, an SAP Remote error?
I've googled alot but didn't find anything.
Maybe someone knows whats the Problem here.
Im using SAP 720.
System.Runtime.InteropServices.COMException (0x000003E9): SAP Remote
Function Call bei
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack) bei
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) ...
Here is my code:
Public FunctionCtrl As Object
Function login_Call()
Try
Dim conn As Object
FunctionCtrl = CreateObject("SAP.Functions")
conn = FunctionCtrl.Connection
conn.System = XXX
conn.ApplicationServer = XXX
conn.SystemNumber = XXX
conn.Client = "XXX"
conn.user = XXX
conn.Password = XXX
conn.Language = XXX
'needed for frontend dialog
conn.RfcWithDialog = True
'log on with logon dialog
If Not conn.Logon(0, 1) Then
Dim WsShell
Dim intText As Integer
WsShell = CreateObject("WScript.Shell")
intText = WsShell.Popup("Logon not succesful." & vbCrLf & _
"will be closed automatically in one minute...", 60)
'conn = Nothing
Anmeldung_Call = False
Exit Function
End If
Anmeldung_Call = True
Catch ex As Exception
Anmeldung_Call = False
End Try
Me.Text = DateTime.Now.ToString()
End Function
Sub Open_IW73()
Dim BdcTable As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim count As Integer
'call transaction IW73
RfcCallTransaction = FunctionCtrl.Add("RFC_CALL_TRANSACTION")
RfcCallTransaction.Exports("TRANCODE") = "IW73"
RfcCallTransaction.Exports("UPDMODE") = "S"
BdcTable = RfcCallTransaction.Tables("BDCTABLE").....
The Error comes in this line: "RfcCallTransaction = FunctionCtrl.Add("RFC_CALL_TRANSACTION")
"
Thank you
I've had the same error. People suggested different fixes like using SAP.functions.Unicode.
What did it for me was simply changing to "RFC_CALL_TRANSACTION_USING". I'm not sure of the exact difference between these commands, so be careful with that. So far it has been working for me though.
im trying to make an insert to my Database and im receiving an error, is my first time with VB.Net so any help would be greatly appreciated.
Here is the code:
Sub InsertGestion(ByVal s As Object, ByVal e As EventArgs)
Dim Records() As String
Records = Split(TBComment.Text, vbCrLf)
Dim record As Integer
For record = 0 To UBound(Records)
oracleCommand = New OracleCommand("INSERT INTO ACTFIL (ACACCTG,ACACCT,ACACTDTE,ACSEQNUM,ACACCODE,ACRCCODE,ACCIDNAM,ACCOMM) values ('1','" + TBNum.text + "','" + TBFecha.Text + "',"+ (record+1) +",'"+TBCodAc.text+"','"+TBCodRes.text+"','"+TBGestor.Text+"','"+record+"')", oracleConexion)
Try
oracleConexion.Open()
oracleCommand.ExecuteNonQuery()
Catch ex As Exception
status.Text = "ERROR al insertar la gestión " + ex.Message + "'" '& ex.Message
Finally
oracleConexion.Close()
Response.Redirect("gestiones.aspx?credito=" + Request.QueryString("credito") + "")
End Try
Next
End Sub
And the Error:
FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +717374
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +114
[InvalidCastException: Conversion from string "INSERT INTO ACTFIL (ACACCTG,ACAC" to type 'Double' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +717687
ASP.marcador_gestiones_aspx.InsertGestion(Object s, EventArgs e) in G:\vta-paqV2\marcador\gestiones.aspx:62
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
This was originally an update and it was working, i just modified the OracleCommand.
Btw, i notice this is not a secure way to execute the queries, if someone can point me on the right direction i'd really appreciate it.
Extract the oracle command from the query and run on Oracle client. That will let you know if there is anything wrong with your oracle command.
Secondly you can use string.format to form your query rather using + operator.
Secure approach to deal with query inputs is through input parameters. You can check below links.
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracleparameter.aspx
http://blogs.msdn.com/b/alextch/archive/2007/08/21/using-data-parameters-with-oracle-data-provider-for-net.aspx
I hope this helps.
Thanks!
Dhananjay