VB IDE and ObjectContext

VB IDE and ObjectContext

A myth that is still being spread in various VB and MTS/COM+ related newsgroups, is that an application can not obtain a reference to the MTS or COM+ ObjectContext in the Visual Basic Integrated Development Environment (VB IDE).

Ever since VB 5 a VB ActiveX DLL project in the IDE can obtain a reference to the MTS ObjectContext object.

This article explains a little bit about how to use this capability, some things to check if it doesn’t seem to be working for your project and detailed instructions for creating a VB application that demonstrates the capability.

This article applies equally to Windows NT (Server or Workstation) with MTS 2.0 installed and Windows 2000 Professional or Server. For easier reading, I’ll refer to both situations as MTS.

Hyperlinks to documentation mentioned in this article can be found at the end of this article

Background – the MTS context object

When code in client application instantiates an object of an MTS component, MTS provides a context object that the code in the component can interact with. Code in an MTS component is not required to interact with the context object, but it normally does, at least to the extent of calling the SetAbort or SetComplete methods. Application code acquires a reference to the MTS context object by calling the GetObjectContext function.

A call to GetObjectContext will terminate normally whether the code making the call is in a component configured as an MTS component or not. If the code is not in configured as an MTS component, GetObjectContext returns the value Nothing.

An MTS component is always a COM DLL (ActiveX DLL in VB parlance). Each MTS Server Package (applications in Windows 2000 Component Services terminology) gets a process of its own and all components in that package execute in the same process. MTS Library packages run in the process of the client.

The VB Integrated Development Environment (VB IDE)

The VB IDE is a normal Windows executable and runs in it own process. So, how can code executing in the VB IDE be part of an MTS component?

For VB version 5 and 6, Microsoft provides a behind the scenes mechanism to overcome this technical difficulty. Without attempting to explain exactly how this works (I don’t understand all the details myself), this mechanism allows ActiveX DLL VB projects executing in the VB IDE to obtain a reference to the MTS context object. The mechanism is available automatically when MTS 2.0 (from the NT Option Pack) and VB 5 or 6 are installed. It is also available automatically when VB is installed under Windows 2000.

The VB Version differences:

VB 5:

Support for debugging MTS components with Version 5 of VB is somewhat primitive. VB 5 uses a special version of GetObjectContext and the associated context object which allows code executing in the VB IDE to obtain a reference to a simulated context object. This simulated object allows calls to SetAbort, SetComplete etc. to execute without error, but the calls have no affect on anything. To get this to work, you have to add the registry entry:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftTransaction ServerDebugRunWithoutContext

This, and limitations that apply in this environment, are explained in the Microsoft Knowledge Base Article Q188919.

VB 6

Support for debugging MTS components with Version 6 of VB is far superior to that for VB Version 5. VB 6 MTS connects the component executing in the VB IDE with the real (not simulated) MTS run-time. There are a few limitations imposed by the debugging environment, such as only one thread of execution and thus only one client at a time can use the component executing in the VB IDE. The Microsoft Transaction Server (MTS) Issues section of the VB Readme file that accompanies Visual Studio 6 (READMEVB.HTM) explains the limitations fairly well and is the first place too look for additional information. This Readme is installed in the root of the Visual Studio folder (typically c:Program FilesMicrosoft Visual Studio). It’s also available as Microsoft Knowledge Base Article Q170156.

The registry key that is required for VB 5 is ignored by and therefor not required for VB 6.


Here are a few of the main points from the VB 6 Readme mentioned above.

  • To avoid certain kinds of problems, it is recommended that components being debugged in the VB IDE not be configured under MTS. If your component is already registered as an MTS component on the development computer, you might want to delete it from MTS before opening it in the VB IDE. In my experience, this is good advice, despite many suggestions to the contrary in newsgroup posts.
  • You can not execute a component in the VB IDE while it is active in MTS. If you choose to ignore the advice above, you must make sure the component is Shut Down in MTS before starting it in the VB IDE.
  • Components in the VB IDE always run in an MTS Library package. Under NT 4.0 and MTS 2.0, this means that testing of code that interrogates security related information in the MTS context object may behave differently in the VB IDE from when the component is configured in a Server package. This is especially the case if the component implements programmatic security (e.g. the IsSecurityEnabled method will always return False). Under Windows 2000 with COM+, Library application security behaves differently; testing security related code may be less of problem. However, there still may be differences when the application is configured as a Server application (for example, see MS KB article Q243437).
  • If you try to “watch” a property of the context object or any associated objects, you may get an unexpected result or a failure in the VB IDE.

Some other things to keep in mind (not in the VB ReadMe):

  • Although VB allows you to have multiple VB Projects active in a single instance of the VB IDE, it’s a really good idea to start your client and components each in separate instances of VB. If you don’t, the VB IDE may crash if you terminate execution of the MTS component (e.g. by clicking on the “End” button on the Debugging toolbar).
  • When debugging a VB component invoked by IIS, the security environment for IIS and the VB IDE must be the same (see MS KB Article Q244807). Disable anonymous access to the asp page, so that IIS must validate the user through integrated security, thus getting the same identity as the component.

If the call to GetObjectContext returns Nothing in the VB IDE

Here are a few things to check if your code can’t obtain a reference to an ObjectContext object in the VB IDE:

  • Is your VB Project an ActiveX DLL? In the VB IDE click Project, Properties and make sure the Project Type: is ActiveX DLL. Other types of VB Projects can not be MTS components.
  • Is the Class Module’s Instancing Property 5-MultiUse and is its MTSTransactionMode property something other than 0-NotAnMTSObject? An MTS component has to have at least one Multi-Use Class Module with its MTSTransactionMode other than 0. When MTSTransactionMode is set to 0-NotAnMTSObject, the VB IDE will not be connected to the MTS run-time and GetObjectContext will always return Nothing.
  • Is the Distributed Transaction Co-ordinator (DTC) service running? Unless this service is running, your MTS component will not be able to obtain a reference to a context object if the class’s MTSTransactionMode is other than 1 NoTransactions. Usually, the first time you attempt to start an MTS component that may use transactions in the VB IDE, you get a warning if DTC is not running. However, you may not get this warning. Check in the Services dialog to make sure DTC is running (see step 9 for additional information).
  • Perhaps the VB6debug.dll file is missing or damaged. This dll implements the interaction between the VB IDE and MTS. The original VB6 version is in the VB98 folder of CD #1 for Visual Studio 6. An updated version is in SP3 and SP4 for Visual Studio (VS6sp3_3.cab and VS6sp43.cab respectively). This file lives in the VB98 folder of the Visual Studio installation folder (e.g. Program FilesMicrosoft Visual StudioVB98).

Instructions for building and testing a VB MTS component and client

The application built using the instructions below consists of two parts: an MTS component and a client EXE. The function implemented is trivial (return a Boolean variable indicating whether the MTS component is in an MTS Transaction or not), but it demonstrates obtaining a reference to an MTS context object and getting properties from that object in the VB IDE.

  1. Start VB 6 (I’m using SP4, but this also should work with no or earlier SPs).
  2. If you get the New Project dialog box, select ActiveX DLL on the New tab, then click Open. If you don’t get that dialog, select File, New Project, ActiveX DLL then click OK.
  3. In the Class Properties box for Class1, set Instancing to 5 – MultiUse and MTSTransactionMode to 2 – Requires Transaction.
  4. From the menu, select Project, References, scroll down, put a check mark beside Microsoft Transaction Server Type Library (if you are running under Windows 2000, choose COM+ Services Type Library instead) and click OK.
  5. In the Project content sub-window, click on Class1 to make sure it is selected.
  6. Paste the following code into the code window. This code returns True if the component is in a transaction and False if not.
  7. Public Function GetTransactionStatus() As Boolean
    Dim CSContext As ObjectContext
    Set CSContext = GetObjectContext()
    GetTransactionStatus = CSContext.IsInTransaction
    Set CSContext = Nothing
    End Function

  8. In the menu, click Project, Project1 Properties, select the Debugging tab and make sure that the Wait for components to be created radio button is selected; click OK.
  9. Click File, Save Project As and save the class module and the project in a suitable folder.
  10. From the Debug Toolbar (or Debug menu), click Step into. You get a warning about using Binary Compatibility Mode, building a DLL etc. Click Yes to continue anyway. You may also get a warning that the Microsoft Distributed Transaction Co-ordinator is not running. Your code can not get a reference to an MTS context object unless DTC is running, so, cancel the warning, open the Services dialog (NT Control Panel, Services; Windows 2000 Start, Programs, Administrative Tools, Services) and start the Distributed Transaction Co-ordinator service, then click Step into again.
    At this point, your component has been compiled, temporarily registered with MTS and is ready to be instantiated by a client.
  11. Open a new instance of VB and create a new Standard EXE project.
  12. In the Project content sub-window, select Project1, then in the Properties window, change the name to Project1Client.
  13. In the Project content sub-window, right click on Form1 and select View Code.
  14. From the menu, select Project, References. Scroll down to Project1 and put a check mark in its box. When you click on Project1, you will see the path to its VBP file in the bottom part of the dialog box. Click OK.
  15. From the drop down list boxes at the top of the code window, in the left side, select Form.
  16. In the Form_Load procedure, paste the following code
  17. Dim TransStatus As Boolean
    Dim obj As Project1.Class1

    Set obj = New Project1.Class1
    TransStatus = obj.GetTransactionStatus()
    Set obj = Nothing

    If TransStatus Then
    MsgBox ("Project1 is in a transaction")
    MsgBox ("Project1 is not in a transaction")
    End If

  18. From the Debug Toolbar, click Step into.
  19. Step through the code in both the client and Project1 and when you get to the statement:
  20. GetTransactionStatus = CSContext.IsInTransaction

    observe that CSContext has a reference to the MTS context object (it is not Nothing).

  21. Click Step Into again and observe that GetTransactionStatus is assigned True.
  22. Keep stepping through the code and you get the message box that says Project1 is in a transaction.

Web Site References – Documentation:


Visual Studio/Visual Basic Version 6 Readme: Transaction Server (MTS) Issues


MS KB article Q188919: HOWTO: Avoid “Error 91” when Debugging MTS Components with Visual Basic. This article applies to VB Version 5 only (not Version 6).


MS KB article Q244807: PRB: Object Required Error for ObjectContext Under Windows 2000 in Visual Basic IDE and Active Server Pages. This article applies to VB Version 6 and Windows 2000.


MS KB article Q243437: PRB: Identity Different in MTS and COM+ Library Package by Default. This article describes differences in how security is implemented between MTS under NT 4.0 and COM+ under Windows 2000.




Share the Post:
Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1

Copilot Revolution

Microsoft Copilot: A Suit of AI Features

Microsoft’s latest offering, Microsoft Copilot, aims to revolutionize the way we interact with technology. By integrating various AI capabilities, this all-in-one tool provides users with an improved experience that not

AI Girlfriend Craze

AI Girlfriend Craze Threatens Relationships

The surge in virtual AI girlfriends’ popularity is playing a role in the escalating issue of loneliness among young males, and this could have serious repercussions for America’s future. A

AIOps Innovations

Senser is Changing AIOps

Senser, an AIOps platform based in Tel Aviv, has introduced its groundbreaking AI-powered observability solution to support developers and operations teams in promptly pinpointing the root causes of service disruptions