Microsoft KB Archive/202535

= INFO: Use of New Keyword In MTS Environment =

Article ID: 202535

Article Last Modified on 8/11/2005

-

APPLIES TO


 * Microsoft Visual Studio 6.0 Enterprise Edition
 * Microsoft Visual Studio 97 Service Pack 3
 * 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 Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition

-



This article was previously published under Q202535



SUMMARY
Use of the VB New keyword to instantiate Microsoft Transaction Server (MTS) components may cause an unexpected behavior. The use of the New keyword in MTS sits in on the COM creation calls, but these methods go beneath COM to instantiate object, the instantiation can not be detected by MTS. The object then runs outside of the MTS environment rather than within. This can cause all sorts of erratic behaviors with MTS:
 * Calls fail
 * Calls may run in a transaction other than anticipated or not at all
 * Calls may not be released as anticipated

Specifics:

C++:

Since a COM interface is at some point a C++ class, it is possible to call "New" on the underlying C++ class. This may give a slight performance improvement, but causes the preceding problems. Always use the COM instantiation functions (CoCreateInstance, etc.) to instantiate MTS components.

Visual Basic (VB):

The VB New keyword uses the COM instantiation functions in most cases and therefore behaves as expected. However, if "New" is used to instantiate an instance of a class in the same project (dll once compiled) then VB uses a non-COM method for performance reasons. This method is much like the C++ equivalent. If 'New' is used to instantiate an instance of a class in separate DLLs then new object is created in a new activity.

NOTE: use ObjectContext's CreateInstance method to create one MTS component from another MTS component.

