Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

Figure 1 Object Design

figure 1 Object Design
Figure 2 Transactional Object Design
figure 2 Transactional Object Design
Figure 3 Ax.dll Code

Option Explicit

Const sconn = _     
    "Provider=sqloledb;server=(local);database=pubs;uid=sa;pwd="

Public Function ExecFailedSPROC() As Integer

    On Error GoTo errorhandler
    
    Dim ctx As ObjectContext
    Dim conn As ADODB.Connection
       
    Set ctx = GetObjectContext()
    
    Set conn = New ADODB.Connection
    
    conn.Open sconn
  
    Call conn.Execute("spRaiseError")
    
    ctx.SetComplete
    
Exit Function

errorhandler:
    If conn.Errors.Count > 0 Then
        Dim errObj As ADODB.Error
        For Each errObj In conn.Errors
            Debug.Print errObj.Description
            Debug.Print errObj.NativeError
            Debug.Print errObj.Number
            Debug.Print errObj.Source
        Next
    Else
        Debug.Print Err.Description
        Debug.Print Err.Number
    End If
    ctx.SetAbort
    Exit Function
End Function
Figure 4 Revised Ax.dll Code

Option Explicit

Const sconn = _
    "Provider=sqloledb;server=(local);database=pubs;uid=sa;pwd="

Public Function ExecFailedSPROC() As Integer

    On Error GoTo errorhandler
    
    Dim ctx As ObjectContext
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    Set ctx = GetObjectContext()
    
    Set conn = New ADODB.Connection
    
    conn.Open sconn
  
    Set rs = conn.Execute("spRaiseError")
    
    Do Until rs Is Nothing
        rs.NextRecordset
    Loop
    ctx.SetComplete
    
Exit Function

errorhandler:
    If conn.Errors.Count > 0 Then
        Dim errObj As ADODB.Error
        For Each errObj In conn.Errors
            Debug.Print errObj.Description
            Debug.Print errObj.NativeError
            Debug.Print errObj.Number
            Debug.Print errObj.Source
        Next
    Else
        Debug.Print Err.Description
        Debug.Print Err.Number
    End If
    ctx.SetAbort
    Exit Function
End Function
Show:
© 2015 Microsoft