Dirty Developer
Dirty Developer

Reputation: 562

"The handle is invalid" execption recevied while creating the object of MQ Queue Manager

Please find the below code:

MQEnvironment.Hostname = HostName;
        MQEnvironment.Channel = Channel;

        if (!string.IsNullOrEmpty(SSLKeyRepository))
        {
            MQEnvironment.SSLCipherSpec = SSLCipherSpec;
            MQEnvironment.SSLKeyRepository = SSLKeyRepository;
        }
        if (Port > 0)
            MQEnvironment.Port = Port;

        try
        {
            MQManager = new MQQueueManager(QueueManager);
            try
            {
                MQRequestQueue = MQManager.AccessQueue(QueueNameGet, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
                MQResponseQueue = MQManager.AccessQueue(QueueNameGet, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);                     
                return true;
            }
            catch (IBM.WMQ.MQException exIBM)
            {
                CloseConnection();
                ErrorCode = exIBM.Reason;
                ErrorDescription = exIBM.Message;
                                }
        }
        catch (IBM.WMQ.MQException exIBM)
        {
            CloseConnection();
            ErrorCode = exIBM.Reason;
            ErrorDescription = exIBM.Message;
        }
        catch (Exception ex)
        {
            CloseConnection();
            ErrorCode = Constants.SYSTEMEXCEPTION;
            ErrorDescription = ex.Message;
        }
        return false;

Issue: I am not getting the issue when I run it for single or 2-3 times. But I get the issue when it runs in a loop for multiple times. Also, I have tried to run the same piece of code for 10,000 times from the IIS server and it ran successfully.

I am getting the issue only when I have this code on IIS webservice and that webservice is getting called multiple times.

IBM MQ client 7.5.0.0 installed on the IIS server and I am using the dll of the same version.

UPDATE Error description:

Error Message The handle is invalid
StackTrace at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly) at System.Diagnostics.Process.get_Modules() at IBM.WMQ.CommonServices.TraceEnvironment() at IBM.WMQ.CommonServices.CreateCommonServices() at IBM.WMQ.CommonServices.TraceEnabled() at IBM.WMQ.MQBase..ctor() at IBM.WMQ.MQManagedObject..ctor()

Upvotes: 0

Views: 383

Answers (2)

Shashi
Shashi

Reputation: 15283

Thanks for providing the call stack. The issue you mention is very similar to the one fixed here in MQ version 7.5.0.2. As you are at MQ v7.5.0.0, I suggest you to upgrade your MQ client to the latest level, MQ v7.5.0.7 and try.

Upvotes: 1

Roger
Roger

Reputation: 7506

I have said this many times here and it applies to both Java and .NET, the MQEnvironment class is NOT thread safe. By using it, you are shooting yourself in the foot.

Put the values (channel, hostname & port #) into a HashTable and pass the HashTable to the MQQueueManager class.

Hashtable qMgrHT = new Hashtable();
qMgrHT.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

qMgrHT.Add(MQC.HOST_NAME_PROPERTY, "10.10.10.10");
qMgrHT.Add(MQC.CHANNEL_PROPERTY, "TEST.CHL");
qMgrHT.Add(MQC.PORT_PROPERTY, 1414);

qMgrHT.Add(MQC.USER_ID_PROPERTY, "myUserID");
qMgrHT.Add(MQC.PASSWORD_PROPERTY, "myPwd");

MQQueueManager qMgr = new MQQueueManager(qManager, qMgrHT);

Finally, write your code so that it maintains a connection rather than connecting and disconnecting over and over. Very, VERY bad form.

Upvotes: 0

Related Questions