INFO: Do Not Use ObjectContext in Class_Initialize and Class_Terminate Events
ID: Q250309
|
The information in this article applies to:
-
Microsoft Transaction Server 2.0
-
Microsoft Visual Basic, version 6.0
SUMMARY
Every Microsoft Transaction Server (MTS) object has an associated context object. The context object provides context for the execution of an instance, including transaction, activity, and security properties. When an MTS object is created, MTS automatically creates a context object for it. When the MTS object is released, MTS automatically releases the context object.
You can access an MTS object's context by calling the GetObjectContext function. The GetObjectContext function returns a reference to the IObjectContext interface. The context object is not available during calls to the component's Class_Initialize and Class_Terminate event. If you call one of its methods then the following error message will appear:
Run-time error '91':
Object variable or With block variable not set
MORE INFORMATION
Simple Server
- Open a new ActiveX DLL project in Visual Basic.
- From the Project menu, select References and Set "Reference to Microsoft Transaction Server Type Library".
- In class properties set MTSTransactionMode to anything other than NotAnMTSObject and add the following code.
Private mobjContext As ObjectContext
Private Sub Class_Initialize()
Set mobjContext = GetObjectContext()
End Sub
Private Sub Class_Terminate()
Set mobjContext = Nothing
End Sub
Public Sub Test()
mobjContext.SetComplete
End Sub
- Compile the component and recompile with Version Compatibility to Binary Compatible.
- Register the component with MTS.
Simple Client
- Open a Standard EXE Visual Basic application to test the component.
- Add a button to Form1.
- Add the following code to Command1_Click().
Private Sub Command1_Click()
Dim o As Object
Set o = CreateObject("project1.class1")
o.Test
End Sub
- Run the client application and click the button. The following error message appears:
Run-time error '91':
Object variable or With block variable not set
- You can resolve this issue by changing the Simple Server code to the following:
Implements ObjectControl
Private mobjContext As ObjectContext
Public Sub Test()
mobjContext.SetComplete
End Sub
Private Sub ObjectControl_Activate()
Set mobjContext = GetObjectContext()
End Sub
Private Function ObjectControl_CanBePooled() As Boolean
End Function
Private Sub ObjectControl_Deactivate()
Set mobjContext = Nothing
End Sub
REFERENCES
For additional information, please see the following article(s) in the
Microsoft Knowledge Base:
Q170156 INFO: VB 6.0 Readme Part 12: Transaction Server (MTS) Issues
Additional query words:
Keywords : kbMTS kbMTS200 kbVBp600 kbDSupport
Version : winnt:2.0; :6.0
Platform : winnt
Issue type : kbinfo