PRB: Source and Description Blank when Using Err.Raise from MTS and ASP

ID: Q238082


The information in this article applies to:
  • Microsoft Transaction Server, versions 1.0, 2.0
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Windows NT 4.0 SP4
  • Active Server Pages
  • ActiveX Data Objects (ADO), versions 1.0, 1.5, 2.0, 2.01, 2.1, 2.1 SP1, 2.1 SP2
  • Microsoft Internet Information Server versions 4.0, 5.0


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

This behavior is by design.


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:
    
    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=sa;PWD="  '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'.

Additional query words:

Keywords : kbADO kbADO100 kbADO150 kbADO200 kbADO201 kbADO210 kbASP kbCOMt kbMTS kbMTS100 kbVBp500 kbVBp600 kbNTOS400sp1 kbADO210sp2 kbiis400 kbiis500
Version : WINDOWS:1.0,1.5,2.0,2.01,2.1,2.1 SP1,2.1 SP2,5.0,6.0; winnt:1.0,2.0,4.0 SP4
Platform : WINDOWS winnt
Issue type : kbprb


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.