Calling a function gives me very unhelpful error message
-
Im trying to debug a function in VB My code looks like this. When I call Dim Ip as Int64 = GetLocId("192.168.1.1, cn) I get error "Syntax error or access violation" Its got to be something stupid I am doing. Namespace Ip Public Class Class1 Public Function GetLocId(ByVal Ip As String, ByVal connection As String) As Int64 Dim cn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(connection) Dim command As String = "EXEC [dbo].[sp_location_i]" 'Dim IpId As Int64 Dim IpLocId As Int64 cn.Open() Dim cmd As System.Data.OleDb.OleDbCommand = cn.CreateCommand() cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = command Dim pIp As OleDbParameter = cmd.Parameters.Add("@Ip", OleDb.OleDbType.VarChar, 15) pIp.Value = Ip Dim pIpLocId As OleDbParameter = cmd.Parameters.Add("@IpLocId", OleDbType.BigInt) pIpLocId.Direction = ParameterDirection.Output 'Try cmd.ExecuteNonQuery() 'Catch exc As OleDbException ' Console.WriteLine(exc.Message) ' IpLocId = 0 --Unknow location 'Finally cn.Close() 'End Try IpLocId = Convert.ToInt64(pIpLocId.Value) Return IpLocId End Function End Class End Namespace
-
Im trying to debug a function in VB My code looks like this. When I call Dim Ip as Int64 = GetLocId("192.168.1.1, cn) I get error "Syntax error or access violation" Its got to be something stupid I am doing. Namespace Ip Public Class Class1 Public Function GetLocId(ByVal Ip As String, ByVal connection As String) As Int64 Dim cn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(connection) Dim command As String = "EXEC [dbo].[sp_location_i]" 'Dim IpId As Int64 Dim IpLocId As Int64 cn.Open() Dim cmd As System.Data.OleDb.OleDbCommand = cn.CreateCommand() cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = command Dim pIp As OleDbParameter = cmd.Parameters.Add("@Ip", OleDb.OleDbType.VarChar, 15) pIp.Value = Ip Dim pIpLocId As OleDbParameter = cmd.Parameters.Add("@IpLocId", OleDbType.BigInt) pIpLocId.Direction = ParameterDirection.Output 'Try cmd.ExecuteNonQuery() 'Catch exc As OleDbException ' Console.WriteLine(exc.Message) ' IpLocId = 0 --Unknow location 'Finally cn.Close() 'End Try IpLocId = Convert.ToInt64(pIpLocId.Value) Return IpLocId End Function End Class End Namespace
I think problem is with this :-
DerekFL wrote:
Dim command As String = "EXEC [dbo].[sp_location_i]"
Change the
Dim command
line toDim command as String = "dbo.sp_location_i"
. leave out theEXEC
.Steve Jowett ------------------------- It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
-
I think problem is with this :-
DerekFL wrote:
Dim command As String = "EXEC [dbo].[sp_location_i]"
Change the
Dim command
line toDim command as String = "dbo.sp_location_i"
. leave out theEXEC
.Steve Jowett ------------------------- It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)