Use CreateInstance Compared to CreateObject and New in MTS

The New keyword in VB is used to create a new instance of a class as an object for use within the current application. When used in a component within Microsoft Transaction Server (MTS), it creates a Private instance of an object that MTS knows nothing about. It won’t have its own context object, and won’t be included within the current transaction. In other words, it has to look after itself with no help from MTS. The CreateObject method is almost exactly the opposite. When used in a component running within MTS, this method creates a new instance of an object that MTS will treat as separate from the current component instance and it will get its own context object. However, the new instance will not contain any information from the context of the component that created this new instance, so it will run outside the current transaction. The CreateInstance method of the context object provides a solution to these two problems. It creates a new instance of the referenced component and provides it with a new context object. However, it also copies the transaction information from the context of the object that created it into the new context thus making it part of the current transaction. Therefore, you should use CreateInstance as opposed to CreateObject and New as it is more versatile in MTS environment.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: