Connecting .Net Service to IBM WebSphere `MQRC_CONNECTION_BROKEN` error

Viewed 25

We have a .NET framework 4.5.2 service running that connects to a WebSphere MQ Server (v7.5.0.9). Our service needs to connect to a Queue and put a message. It doesn’t need to receive anything after putting the message. We have this set up in a Test and Production environment. We've had this running for a while without any issues. Now we are facing an error only in the Production environments. The same code works fine in the Test environment. But Production is showing very inconstant results and we are unable to recreate the issue anywhere else.

The only way we are currently able to get it working is by restarting the .NET service multiple times until the service is able to connect to all Queue Managers. Every time we restart the service we get a different result. We may start the service and it would not be able to connect to any of the Queue Managers and then we restart again and 2 of the Queue Managers are able to connect. Once the connection has been made it is stable, the service will be able to put messages in any of the Queues without it ever disconnecting.

Some of the things we have tried

  • Before this issue, we were using the SYSTEM.DEF.SVRCONN channel to connect to the Queue Managers but we have changed that to use a "Server Connection" channel we have created in each Queue Manager. We can see the new channels are in an Active state but only if it is able to make the initial connection.
  • Originally we were connecting to a Queue Manager, putting a message, and closing the Queue but we were leaving the Queue Manager open. We have tried to Close and Disconnect the Queue Managers after every message but that seemed to make things worse.
  • The .Net service and Websphere are on the same box but we have tried disabling the windows firewall on the server in case there was something blocking it. That didn’t seem to make a difference either.

My background is in .NET so I'm not very familiar with the WebSphere UI and even less with the CLI. Any ideas on places to look or commands to run to get any insight on what is going on would be helpful.

The only error we get in WebSphere is "CompCode: 2, Reason: 2009" but in the service we are catching the exception, it says "Error Message: MQRC_CONNECTION_BROKEN"

Below is the code used to connect and send a message. We are using the amqmdnet.dll

    try
    {
        properties = new Hashtable();
        properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
        properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
        properties.Add(MQC.PORT_PROPERTY, port);
        properties.Add(MQC.CHANNEL_PROPERTY, channelName);
        if (!QueueManagers.ContainsKey(queueManagerName))
        {
            queueManager = new MQQueueManager(queueManagerName, properties);
            QueueManagers[queueManagerName] = queueManager;
        }
        else
        {
            queueManager = QueueManagers[queueManagerName];
            if (!queueManager.IsConnected)
            {
                queueManager = new MQQueueManager(queueManagerName, properties);
                QueueManagers[queueManagerName] = queueManager;
            }
        }
        queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
        message = new MQMessage();
        message.ClearMessage();
        message.Format = MQC.MQFMT_STRING;
        message.Encoding = MQC.MQENC_NATIVE;
        message.CorrelationId = MQC.MQCI_NONE;
        message.CharacterSet = MQC.MQCCSI_Q_MGR;
        message.WriteString(messageString);
        queue.Put(message);
    }
    catch (Exception ex)
    {
        sentToMQServer = false;
        QueueManagers.TryRemove(queueManagerName, out var mgr);
        queueManager?.Close();
        queueManager?.Disconnect();
    
        if (retry)
            SendToMQServer(remoteClient, Message, false);
    }
    finally
    {
        message = null;
        //QueueManagers.TryRemove(queueManagerName, out var mgr);
    
        if (properties != null)
        {
            properties.Clear();
            properties = null;
        }
        if (queue != null)
        {
            queue.Close();
            queue = null;
        }
    
        //queueManager.Close();
    
        //queueManager.Disconnect();
}
0 Answers
Related