Hi,
I have the following code to retrieve error and print messages. I was using the sqloledb driver. Unfortunately, I was not successful, and then I found a message on this forum saying that with sqloledb we can only obtain 1 message. As a result, I switched to MSDASQL (it was advised to do so). Now I am getting 1 more error messages and then the execution of the procedure just stops. Can someone help me understand what is wrong with my code?
Module Module1
Sub Main()
On Error GoTo ErrHandler
Dim myConn
Dim myCmd
Dim myRs
Dim myConnStr As String
myConnStr = "driver={SQL Server};server=APPD;database=Rk;Trusted_Connection=Yes"
' instantiate the ADO objects
myCmd = CreateObject("ADODB.Command")
myRs = CreateObject("ADODB.Recordset")
myConn = CreateObject("ADODB.Connection")
With myConn
.Provider = "MSDASQL"
.CursorLocation = 3
.ConnectionString = myConnStr
.Open()
End With
myCmd.ActiveConnection = myConn
With myCmd
.CommandType = 4
.CommandText = "process_hierarchy" 'sArgs(2)
End With
' execute the command
myRs = myCmd.Execute
myCmd = Nothing
myRs = Nothing
myConn = Nothing
Do While (Not myRs Is Nothing)
If myRs.State = 0 Then Exit Do
myRs = myRs.NextRecordset
Loop
GoTo Shutdown
ErrHandler:
Call ErrHandler(myConn)
Resume Next
Shutdown:
myCmd = Nothing
myRs = Nothing
myConn = Nothing
End Sub
Sub ErrHandler(ByVal objCon As Object)
Dim myErr
Dim strError As String
myErr = CreateObject("ADODB.Error")
For Each myErr In objCon.Errors
strError = myErr.Description
'MsgBox(strError)
Next
objCon.Errors.Clear()
End Sub
End Module
I have the following code to retrieve error and print messages. I was using the sqloledb driver. Unfortunately, I was not successful, and then I found a message on this forum saying that with sqloledb we can only obtain 1 message. As a result, I switched to MSDASQL (it was advised to do so). Now I am getting 1 more error messages and then the execution of the procedure just stops. Can someone help me understand what is wrong with my code?
Module Module1
Sub Main()
On Error GoTo ErrHandler
Dim myConn
Dim myCmd
Dim myRs
Dim myConnStr As String
myConnStr = "driver={SQL Server};server=APPD;database=Rk;Trusted_Connection=Yes"
' instantiate the ADO objects
myCmd = CreateObject("ADODB.Command")
myRs = CreateObject("ADODB.Recordset")
myConn = CreateObject("ADODB.Connection")
With myConn
.Provider = "MSDASQL"
.CursorLocation = 3
.ConnectionString = myConnStr
.Open()
End With
myCmd.ActiveConnection = myConn
With myCmd
.CommandType = 4
.CommandText = "process_hierarchy" 'sArgs(2)
End With
' execute the command
myRs = myCmd.Execute
myCmd = Nothing
myRs = Nothing
myConn = Nothing
Do While (Not myRs Is Nothing)
If myRs.State = 0 Then Exit Do
myRs = myRs.NextRecordset
Loop
GoTo Shutdown
ErrHandler:
Call ErrHandler(myConn)
Resume Next
Shutdown:
myCmd = Nothing
myRs = Nothing
myConn = Nothing
End Sub
Sub ErrHandler(ByVal objCon As Object)
Dim myErr
Dim strError As String
myErr = CreateObject("ADODB.Error")
For Each myErr In objCon.Errors
strError = myErr.Description
'MsgBox(strError)
Next
objCon.Errors.Clear()
End Sub
End Module