PRB: Visual Basic MTS/COM+ Components Should Not Implement Class_Initialize (278501)
The information in this article applies to:
- Microsoft Transaction Server 2.0
- Microsoft COM+ 1.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q278501 SYMPTOMS
Code in the Class_Initialize method of a Visual Basic ActiveX dynamic-link library (DLL) can cause stability issues when the DLL is installed into Microsoft Transaction Server (MTS) or COM+ Services. In MTS, you may see one or both of the following events written to the Application event log:
Event ID: 4135
Source Transaction Server
Failed on creation within a server process. InitialBind (Package: YourPackage) (ProgId: YourClass.YourObject) (CLSID: {619FD1CF-2DA5-11D4-8A63-00A083360DAC}) (Interface: IClassFactory) (IID: {00000001-0000-0000-C000-000000000046}) (Method: 3) (Microsoft Transaction Server Internals Information: File: d:\viper\src\runtime\context\ccontext.cpp, Line: 2032)
Event ID 4129
Source Transaction Server
The run-time environment caught an exception during a call into your component. This error caused the process to terminate. ~CContext (Package: YourPackage) (ProgId: YourClass.YourObject) (CLSID: {619FD1CF-2DA5-11D4-8A63-00A083360DAC}) (Interface: IClassFactory) (IID: {00000001-0000-0000-C000-000000000046}) (Method: 4) (Microsoft Transaction Server Internals Information: File: d:\viper\src\runtime\context\ccontext.cpp, Line: 1104)
CAUSE
This problem occurs because the Visual Basic run time calls Class_Initialize before MTS creates the context wrapper for the component.
RESOLUTION
Do not implement Class_Initialize in an ActiveX DLL that you are going to install into MTS or COM+. If you need to initialize your object, use a separate initialization method or use the Activate method of the ObjectControl interface instead.
STATUSThis problem was corrected in Microsoft Windows 2000 Service Pack 1.
ObjectContext is now available for Class_Initialize and Class_Terminate.
MORE INFORMATION
In an MTS or COM+ component, the Class_Initialize and Class_Terminate events should not contain code that attempts to access the object or its corresponding context wrapper. The Visual Basic run-time environment calls Class_Initialize before the object and its context are activated. Therefore, any operation in Class_Initialize that attempts to access the object or its context wrapper will fail.
You may also see this behavior with code in the Class_Terminate method. MTS destroys the object and its context wrapper before the Visual Basic run time calls the Class_Terminate method, so code in this event handler can also cause stability issues.
ActiveX Data Objects (ADO) connections that are opened in Class_Initialize will not participate in an MTS or COM+ transaction, because transaction enlistment is controlled by the object context.
REFERENCESFor additional information, click the article number below
to view the article in the Microsoft Knowledge Base:
250309 INFO: Do Not Use ObjectContext in Class_Initialize and Class_Terminate Events
Modification Type: | Major | Last Reviewed: | 6/12/2001 |
---|
Keywords: | kbDSupport kberrmsg kbprb KB278501 |
---|
|