Microsoft Knowledge Base Email Alertz

(238082) - 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...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 238082 - Last Review: July 16, 2004 - Revision: 3.2

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

This article was previously published under Q238082

On This Page

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'.

APPLIES TO
  • Microsoft Transaction Services 1.0
  • Microsoft Transaction Services 2.0
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Active Server Pages 4.0
  • Microsoft ActiveX Data Objects 1.0
  • Microsoft ActiveX Data Objects 1.5
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.01
  • Microsoft ActiveX Data Objects 2.1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Services 5.0
Keywords: 
kbbug kbcodesnippet kbdatabase kbfix kbmdac260fix KB238082
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate