Microsoft KB Archive/248098

= PRB: Run-Time Error Message -2147164145(8004e00f) Method Call on MTS Object from Visual Basic Application Fails =

Article ID: 248098

Article Last Modified on 6/6/2001

-

APPLIES TO


 * Microsoft Windows NT 4.0
 * Microsoft Transaction Services 2.0
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q248098



SYMPTOMS
When you attempt to invoke a method on a Transactional Microsoft Transaction Server (MTS) object from a Visual Basic client application, the following error message is displayed:

Runtime error -2147164145(800e400f): Method [methodname] of object [objectname] failed.



CAUSE
MTS components use the services of the Microsoft Distributed Transaction Coordinator (MS DTC) to incorporate transactional functionality. Invoking methods of an MTS component that call transactional methods of the Objectcontext object, such as SetComplete and SetAbort, may cause the error message. This error message occurs if methods of the MTS component are called, and the MS DTC service has not been started on the Windows NT-based computer that is hosting the component and running Transaction Server.



RESOLUTION
Start the MS DTC service on the Windows NT-based computer that is running Transaction Server in one of two ways:

Method 1:
 * 1) On the Start menu, point to Settings, and then click Control Panel.
 * 2) Double-click Services to open the Services dialog box.
 * 3) Select MSDTC in the list of Services.
 * 4) Click Start to initiate the service.

Method 2:

If the Windows NT-based computer also runs Microsoft SQL Server, use the SQL Server Service manager to start MS DTC.



STATUS
This behavior is by design.



MORE INFORMATION
MTS uses the services of MS DTC to support and incorporate the transactional functionalities of components that are registered in it. Therefore, the MS DTC service must be active for transactional methods of MTS components to be executed successfully. The error message in the "Symptoms" section is not a bug in any of the Microsoft products listed in the Applies to section of this article.

Steps to Reproduce Behavior
NOTE: The following example is included for illustration purposes only. It uses the SQL 7.0 Pubs database, and assumes that the Windows NT Option Pack is installed on the computer that is running Visual Basic. The error message documented in this article can be reproduced by invoking the method of any transactional MTS component with the MS DTC service stopped on the MTS Server computer.

Creating the Sample Visual Basic COM Component
 Create a new ActiveX DLL project in Visual Basic. Rename the Class module from Class1 to clsAuthor, and set its MTSTransactionMode property to 2-RequiresTransactions. Save the project as MTSPubs.vbp, and save the class module as clsAuthor.cls. On the Project menu, click References, and then set a reference to Microsoft ActiveX Data Objects 2.X Library.  Make the following declarations in the General Declarations section of the 'clsAuthor' Class module: Dim cn As ADODB.Connection Dim rs As ADODB.Recordset </li>  Initialize and open the ADO Connection object in the Class_Initialize event as shown in the following code. Replace the connection string with one that points to your SQL Server. Private Sub Class_Initialize Set cn = New ADODB.Connection cn.ConnectionString = "Provider=SQLOLEDB;Data Source=RAVINDK1;Initial Catalog=pubs;Trusted_Connection=yes" cn.Open End Sub </li>  Add a method called GetAuthors that constructs and returns a disconnected recordset from the Pubs database that contains records from the Authors table as follows: Public Function GetAuthors As Object Set rs = New ADODB.Recordset Set rs.ActiveConnection = cn rs.LockType = adLockBatchOptimistic rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.Open "Select au_fname, au_lname from Authors" Set rs.ActiveConnection = Nothing Set GetAuthors = rs GetObjectContext.SetComplete End Function </li> Save the project, on the File menu, choose Make MTSPubs.dll to compile the DLL, and then close Visual Basic.</li></ol>

Installing the Component in MTS

 * 1) Start MTS Explorer, and create a package.
 * 2) Add the component you just created in Visual Basic by right-clicking on the Components folder of the package. Under New, click Component, click Install New Components, and then select the DLL.
 * 3) After the component has been registered in MTS Explorer, check its properties to ensure that its Transaction attribute has been set to Requires Transactions.

Setting Up the Visual Basic Client to Reproduce the Problem
<ol> Create a standard EXE project in Visual Basic to implement the client application that will invoke the MTS component and call its GetAuthors method to retrieve the disconnected recordset. On the Project menu, click References, and then set a reference to the Microsoft ActiveX Data Object 2.X Library.</li> Place a Listbox control on the default Form1, place a Command button beneath the list box, and set its Caption property to Get Authors.</li>  Make the following declarations in the General declarations section of the form module: Dim mauthor As Object Dim aurset As ADODB.Recordset </li>  Place the following code in the Form_Load event to create an instance of the MTSPubs.clsAuthor MTS object: Private Sub Form_Load Set mauthor = CreateObject("MTSPubs.clsAuthor") End Sub </li>  Place the following code in the Click event of the Command button. This code calls the GetAuthors method of the MTS object and returns the disconnected recordset that contains the records from the Authors table in the SQL 7.0 Pubs database. Private Sub Command1_Click Set aurset = mauthor.GetAuthors List1.Clear Do While Not aurset.EOF List1.AddItem aurset.Fields("au_fname") aurset.MoveNext Loop aurset.Close End Sub </li> Save the project as MTSClnt, and save the form as frmTest. Make sure that the MS DTC Service is not running on the Windows NT-based computer. You can shut it down by using the SQL Server Service Manager if the SQL server to which you are connecting is installed on the MTS computer. You can also stop the Msdtc.exe process from the Windows NT task manager.</li> Run your client project, MTSClnt, and note that an instance of your MTS object is created in the Form_Load event. Then the form, frmTest, is displayed.</li> Click on the Command button labeled Get Authors, and note that you receive the following error message:

Runtime error -2147164145(8004e00f): Method 'GetAuthors' of object '_clsAuthor' failed.

</li> Click End to stop the execution of the project, and then return to the design environment.</li> Start the MS DTC service on the MTS computer, rerun the project, and note that when you click on the Get Authors Command button, the list of authors (first name, and last name) is displayed in the list box on the form.</li></ol>

Additional query words: VB 6.0 VB6

Keywords: kbprb kbfaq KB248098

-

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

© Microsoft Corporation. All rights reserved.