Microsoft KB Archive/248098
Article ID: 248098
Article Last Modified on 6/6/2001
- Microsoft Windows NT 4.0
- Microsoft Transaction Services 2.0
- Microsoft Visual Basic 6.0 Enterprise Edition
This article was previously published under Q248098
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:
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.
Start the MS DTC service on the Windows NT-based computer that is running Transaction Server in one of two ways:
- On the Start menu, point to Settings, and then click Control Panel.
- Double-click Services to open the Services dialog box.
- Select MSDTC in the list of Services.
- Click Start to initiate the service.
If the Windows NT-based computer also runs Microsoft SQL Server, use the SQL Server Service manager to start MS DTC.
This behavior is by design.
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
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
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
- Save the project, on the File menu, choose Make MTSPubs.dll to compile the DLL, and then close Visual Basic.
Installing the Component in MTS
- Start MTS Explorer, and create a package.
- 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.
- 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
- 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.
- Place a Listbox control on the default Form1, place a Command button beneath the list box, and set its Caption property to Get Authors.
Make the following declarations in the General declarations section of the form module:
Dim mauthor As Object Dim aurset As ADODB.Recordset
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
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
- 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.
- 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.
- Click on the Command button labeled Get Authors, and note that you receive the following error message:
- Click End to stop the execution of the project, and then return to the design environment.
- 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.
Additional query words: VB 6.0 VB6
Keywords: kbprb kbfaq KB248098