FIX: Source and Description Blank when Using Err.Raise from MTS and ASP (238082)



The information in this article applies to:

  • Microsoft Transaction Server 1.0
  • Microsoft Transaction Server 2.0
  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Active Server Pages
  • ActiveX Data Objects (ADO) 1.0
  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.01
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.1 SP1
  • ActiveX Data Objects (ADO) 2.1 SP2
  • ActiveX Data Objects (ADO) 2.5
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Server 5.0

This article was previously published under Q238082

SYMPTOMS

When raising an error inside a Visual Basic component in a Microsoft Transaction Server (MTS) Server Package that is called from another Visual Basic component in a different MTS Server Package, ASP displays only the error number. The error source and description fields are empty.

RESOLUTION

Make sure that all the object references are set to Nothing before raising the error (particularly for the object that holds the reference to the ObjectContext.CreateInstance of the first component).

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Data Access Components (MDAC) version 2.6.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new ActiveX DLL in Visual Basic 6.0.
  2. Set a reference to the following type libraries:

    Microsoft Transaction Server Type Library

    Microsoft ActiveX Data Objects 2.x Library

  3. Name the project "RaiseError".
  4. Name the class "CRaiseError".
  5. Set the MTSTransactionMode property of the class to "2 - RequiresTransaction".
  6. Add the following method to the class:

    Note You must change UID=<username> and PWD=<strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.
    Public Function RaiseError() As Variant
        Dim cmdADO As New ADODB.Command
        Dim objContext As ObjectContext
        Dim lErrNum As Long
        Dim sErrSrc As String
        Dim sErrDesc As String
    
        On Error GoTo Err_Handler
    
        Set objContext = GetObjectContext
    
        With cmdADO
            .ActiveConnection = "DSN=pubs;UID=<username>;PWD=<strong password>"  'fill in your server credentials here!
            .CommandText = "Not a valid SQL statement"  'This will create an error
            .Execute
        End With
    
        objContext.SetComplete
        Set cmdADO = Nothing
        
        RaiseError = "No Error"
        Exit Function
    Err_Handler:
        Set cmdADO = Nothing
        lErrNum = Err.Number
        sErrSrc = Err.Source
        sErrDesc = Err.Description
        objContext.SetAbort
        Set objContext = Nothing
        Err.Raise lErrNum, sErrSrc, sErrDesc
    End Function
    					
  7. From the File menu, click Add Project, and double-click ActiveX DLL.
  8. Name the project "CallRaiseError".
  9. Name the class "CCallRaiseError".
  10. Set a reference to the following type library:

    Microsoft Transaction Server Type Library

  11. Set the "MTSTransactionMode" property of the class to "2 - RequiresTransaction".
  12. Add the following method to the class:
    Public Function CallRaiseError() As Variant
        Dim objRaiseError   As Object
        Dim objContext      As ObjectContext
        Dim lErrNum         As Long
        Dim sErrSrc         As String
        Dim sErrDesc        As String
        Set objContext = GetObjectContext
    
        On Error GoTo Err_Handler
    
        Set objRaiseError = objContext.CreateInstance("RaiseError.CRaiseError")
        objRaiseError.RaiseError
        objContext.SetComplete
        Set objRaiseError = Nothing
        CallRaiseError = "No Error"
        Exit Function
    Err_Handler:
        lErrNum = Err.Number
        sErrSrc = Err.Source
        sErrDesc = Err.Description
        objContext.SetAbort
        'Set objRaiseError = Nothing 'if you leave this alive no err will be passed
        Set objContext = Nothing
        Err.Raise lErrNum, sErrSrc, sErrDesc
    End Function
    					
  13. From the File menu, select Build Object Group to compile and build the DLL files.
  14. In Transaction Server Explorer, create two new empty MTS Server Packages to host your components.
  15. Copy and Paste the following ASP script into a new ASP file:
    <%
    Option Explicit
    On Error Resume Next
    Dim objCallRaiseError
    Set objCallRaiseError = Server.CreateObject("CallRaiseError.CCallRaiseError")
    Response.Write "Executing Method on CallRaiseError which will execute method from RaiseError<br>"
    objCallRaiseError.CallRaiseError
    If Err.Number Then
    	Response.write("Error Number : " & Err.Number & "<br>")
    	Response.write("Error Source : " & Err.Source & "<br>")
    	Response.write("Error Description : " & Err.Description & "<br>")
    End IF
    Set objCallRaiseError = Nothing 
    %>
  16. Request the ASP page from a browser.
The following result will appear in the browser:

Executing Method on CallRaiseError which will execute Method on RaiseError
Error Number : -2147217900
Error Source :
Error Description :

The expected result was:

Executing Method on CallRaiseError which will execute method from RaiseError
Error Number : -2147217900
Error Source : Microsoft OLE DB Provider for ODBC Drivers
Error Description : [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'Not'.


Modification Type:MinorLast Reviewed:7/16/2004
Keywords:kbbug kbCodeSnippet kbDatabase kbfix kbMDAC260fix KB238082 kbAudDeveloper