Connecting to remote queue manager using C# and .Net

Joe Schmoe picture Joe Schmoe · Nov 4, 2010 · Viewed 16.4k times · Source

I wrote an application that connected to local queue manager using this function call:

MQQueueManager mqQMgr = new MQQueueManager("QM_QueueManagerName");

Now I need to connect to remote queue manager on another computer.

I can successfully connect to remote queue manager using MQ Explorer from my development PC using QM_ComputerName as queue manager name, S_ComputerName as channel and ComputerName as connection name. So it is accessible from my desktop.

However, when I try to connect via .Net I get MQRC_Q_MGR_NAME_ERROR no matter what I try.

I tried specifying

MQEnvironment.Hostname = "ComputerName";
MQEnvironment.Channel = "S_ComputerName ";

and then calling

mqQMgr = new MQQueueManager("QM_ComputerName");

I also tried  calling 

mqQMgr = new MQQueueManager("QM_ComputerName", "S_ComputerName", "ComputerName");

I get error in both cases.

Anyone can advise?

Answer

Joe Schmoe picture Joe Schmoe · Nov 5, 2010

This is how I got it to work:

 MQQueueManager mqQMgr=null;

   Hashtable props = new Hashtable();

props.Add(MQC.HOST_NAME_PROPERTY, "HostNameOrIP");

   props.Add(MQC.CHANNEL_PROPERTY, "ChannelName");

   props.Add(MQC.PORT_PROPERTY, 1414); // port number

   props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

   MQQueue mqQueue = null;

   try

   {

      mqQMgr = new  MQQueueManager("QueueManagerName", props);

      mqQueue = mqQMgr.AccessQueue(
               QueueName,
               MQC.MQOO_OUTPUT                   // open queue for output
               + MQC.MQOO_FAIL_IF_QUIESCING);   // but not if MQM stopping
   }

   catch (MQException mqe1)

   {

   }