I am writing a program to batch copy data from an operating system file into a table in SQL Server 6.5. I have discovered an ActiveX control in the SQL Server programmer's toolkit called VBSQL.OCX which provides several methods to allow me to do this. Here is my code so far:
[tt]Dim login_id As Long, connection_id As Long
Dim rows As Long
login_id = SqlLogin
If SqlBCPSetL(login_id, True) = 0 Then
error = "Failed to enable BCP on the connection"
End If
If SqlSetLUser(login_id, "sa") = 0 Then
error = "Failed to set SQL user"
End If
If SqlSetLPwd(login_id, "sPac31999") = 0 Then
error = "Failed to set SQL password"
End If
connection_id = SqlOpen(login_id, "BISUAT")
If connection_id = 0 Then
error = "Login Failed"
Else
If SqlBCPInit(connection_id, "Shorthaul.dbo.System_Inputs", App.Path & "\inputs.dat", App.Path & "\Errors.log", DBIN) = 0 Then
error = "Failed to initialise BCP operation"
End If
If SqlBCPExec(connection_id, rows) = 0 Then
error = "Failed to complete BCP operation"
Else
MsgBox rows & " rows imported"
End If
SqlExit
SqlWinExit
End If[/tt]
When executed, the application runs until it gets to the [tt]SQLBCPExec[/tt] line. When it tries to run this, it forces the Visual Basic IDE to crash with a message saying that "Visual Basic has encountered a problem and needs to close". Has anybody come across this problem or anything like it?
Dan Griffiths
Software Analyst
National Grid Transco (NGT)
[tt]Dim login_id As Long, connection_id As Long
Dim rows As Long
login_id = SqlLogin
If SqlBCPSetL(login_id, True) = 0 Then
error = "Failed to enable BCP on the connection"
End If
If SqlSetLUser(login_id, "sa") = 0 Then
error = "Failed to set SQL user"
End If
If SqlSetLPwd(login_id, "sPac31999") = 0 Then
error = "Failed to set SQL password"
End If
connection_id = SqlOpen(login_id, "BISUAT")
If connection_id = 0 Then
error = "Login Failed"
Else
If SqlBCPInit(connection_id, "Shorthaul.dbo.System_Inputs", App.Path & "\inputs.dat", App.Path & "\Errors.log", DBIN) = 0 Then
error = "Failed to initialise BCP operation"
End If
If SqlBCPExec(connection_id, rows) = 0 Then
error = "Failed to complete BCP operation"
Else
MsgBox rows & " rows imported"
End If
SqlExit
SqlWinExit
End If[/tt]
When executed, the application runs until it gets to the [tt]SQLBCPExec[/tt] line. When it tries to run this, it forces the Visual Basic IDE to crash with a message saying that "Visual Basic has encountered a problem and needs to close". Has anybody come across this problem or anything like it?
Dan Griffiths
Software Analyst
National Grid Transco (NGT)