How do I auto-connect IBM MQ client?
.net, c#, ibm-mq
Solution
Automatic client reconnection is supported by MQ C# client from v7.1 onwards. You have to use `MQCNO_RECONNECT` or `MQCNO_RECONNECT_Q_MGR` or `MQCNO_RECONNECT_AS_DEF` CNO option to enable automatic reconnection. MQ v7.1 ships couple of samples, SimpleClientAutoReconnectPut.cs is one of them. Please refer to the sample for detail.
Simple snippet.
mqQMgr = new MQQueueManager("QM", MQC.MQCNO_RECONNECT,"SVRCONNCHN","localhost(1414)");
Problem
I am using the MQ.NET classes of the MQ 7x client, and importing and exporting messages works fine. However, if there is a network disconnect or the remote manager is disconnected, the IBM MQ client doesn't automatically reconnect. I get: ``` Error: Remote host ' not available, retry later. ``` Is there a way to auto-connect and continue processing the message when these kind of issues occur? There is a property to check the connection of the queue manager: ``` mqQMgr = new MQQueueManager("My queue manager name" ,"my channel name",",my connection name"); ``` `mqQMgr.IsConnected` returns true/false, but this doesn't help to auto-connect. This is what i am using: ``` // mq properties Hashtable properties = new Hashtable(); properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED); properties.Add(MQC.CONNECTION_NAME_PROPERTY, "connectionName"); properties.Add(MQC.CHANNEL_PROPERTY, "channelName"); properties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT_Q_MGR); mqQMgr = new MQQueueManager("my queue manager"), properties); //error thrown ``` I get this error on the above line ``` IBM MQException caught in send message - reason code - 2046- message -CompCode: 2, Reason: 2046 {"MQRC_OPTIONS_ERROR"} base {System.ApplicationException}: {"MQRC_OPTIONS_ERROR"} CompCode: 2 CompletionCode: 2 Message: "MQRC_OPTIONS_ERROR" Reason: 2046 ```