Microsoft KB Archive/238082

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

Article ID: 238082

Article Last Modified on 7/16/2004

-

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 6.0 Enterprise Edition
 * 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

-



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.



Steps to Reproduce Behavior
 Create a new ActiveX DLL in Visual Basic 6.0. Set a reference to the following type libraries:

Microsoft Transaction Server Type Library

Microsoft ActiveX Data Objects 2.x Library

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

Note You must change UID= and PWD= 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= ;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 </li> From the File menu, click Add Project, and double-click ActiveX DLL.</li> Name the project "CallRaiseError".</li> Name the class "CCallRaiseError".</li> Set a reference to the following type library:

Microsoft Transaction Server Type Library

</li> Set the "MTSTransactionMode" property of the class to "2 - RequiresTransaction".</li>  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 </li> From the File menu, select Build Object Group to compile and build the DLL files.</li> In Transaction Server Explorer, create two new empty MTS Server Packages to host your components.</li>  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 " objCallRaiseError.CallRaiseError If Err.Number Then Response.write("Error Number : " & Err.Number & " ") Response.write("Error Source : " & Err.Source & " ") Response.write("Error Description : " & Err.Description & " ") End IF Set objCallRaiseError = Nothing %> </li> Request the ASP page from a browser.</li></ol>

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: error -2147217900

Keywords: kbbug kbfix kbcodesnippet kbdatabase kbmdac260fix KB238082

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.