"No MTS context" error when trying to connect to MQ Queue Manager

Posted on 2008-11-13
Last Modified: 2013-11-15
I have a C# GUI application and am attempting to connect to an MQ channel using the IBM MQ API (that I have installed on my system).  I have a reference to the amqmdnet.dll DLL in the "C:\Program Files\IBM\WebSphere MQ\bin" folder.

I try to instantiate an MQQueueManager object using the following code:

   IBM.MQ.MQQueueManager qm = new IBM.MQ.MQQueueManager(qmName, channel, connName);

The prototype for the MQQueueManager overloaded constructor used above is:

   public MQQueueManager(string queueManagerName, string Channel, string ConnName);

However, upon executing this line of code, an exception is thrown saying "There is no MTS context available".  I've attached a screenshot.  I've Googled what I've found seems to be the error code for this (0x8004E004), and also a variation on the message ("no MTS object context"), but to no avail.

What's stranger is that I have fetched an earlier version of the code for my project and it works absolutely fine on the same machine.  I've done a diff, but there doesn't appear to be any obvious differences that would impact on this particular function.  I've even done a complete clean and rebuild to force a recompile and relink, and referenced DLLs are the same location on my hard disk.  I'm now at a complete loss.  Can anyone help me with pinpointing what could be causing this particular error?

Thanks for any help!
Question by:Xtreem
    LVL 6

    Expert Comment

    I'm curious if the original code is a Serviced Component (COM+).  Do any of the class definitions look like:
    public class MyClass: ServicedComponent

    Author Comment

    No, that base class isn't used anywhere in the project in the new or old code.

    A few new forms were added since the old code, but nothing that should impact this - they're just new dialogues.
    LVL 6

    Expert Comment


    Do you know if the original working application was a COM+ application.  You should be able to go to Start, Control Panel, Administrator tools, Component Services. Expand Component Services, Select My Computer and expand COM+ Applications.  Scroll through the COM+ applications and see if anything looks like the original application which is working.  
    I am almost certain the application is a Serviced Component (COM+).  The System.EnterpriseServices.DLL leads me to believe this.  
    A Serviced Component dll needs to be registered in the COM+ Catalog Before it can be registered it must be Strongly Named.  Strong Naming happens from the Visual Studio .Net Command prompt by using the sn command from the directory which contains the dll you created.
    Once the dll is strongly named, it can be installed into the Global Assembly Cache (GAC).  While remaining at the Visual Studion .Net Command prompt I would do something like this gacutil /i myDLL.dll This installs the dll into the GAC.  Next, the dll needs to be registered.  I use regsvcs myDLL.dll.
    There are also some other considerations that should be taken such as assigning a GUID to your dll and setting the version number of your assembly.  I would recommend reading up on COM+ components.

    Author Comment

    I've done a search in the old project code in every file (*.*) for "ServicedComponent", but nothing found. But even if there was, this wouldn't have been removed in the latest code.

    The application is an executable GUI Windows Application (.exe) written in C#/.NET.  So, it definitely isn't a COM+ application.  I've checked the Component Services and it isn't listed (see attached file) - The application is called PDCTradeGenerator; PDCWeb is something different.

    Regarding your last three paragraphs, does this apply to a C# Windows Application executable also? Should I be running 'sn', 'gacutil' and 'regsvcs' on my executable?  And also, if so, is it possible that the new code has become unsynchronised with the old code's registering in this way (although, I would have though a complete rebuild would resolve anything like this, and I haven't done anything like this with the old code, I'm simply just building both versions of the project)?
    LVL 6

    Expert Comment

    No, if it an executable then it won't be a COM+ component.  You shouldn't register your executable.
    I know you reference the amqmdnet.dll .  Do you reference any other's within the program?  
    LVL 6

    Expert Comment

    Sorry I had a hard drive which needed to be cloned today and kept me off the net.  I am just getting back on.  I have a few questions which may help me better understand your situation.
    (1) What is different between your new application and the old one?  I am trying to understand the need for the new application.
    (2) What references do you include within your GUI Windows App?
    (3) Did you happen to add database calls within the new one?

    Author Comment

    I found the solution for this eventually, sorry for late update...

    The overloaded constructor for IBM.MQ.MQQueueManager always generates a first-chance exception, but it is safe to ignore this.  It's by design I believe.  The difference between my earlier code and current code was that I had breaking switched on for CLR Exceptions.

    Please close this Question.

    Thanks for everyone's input.
    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    EE Admin

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
    The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
    This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
    The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now