I'm new to WebSphere Message Queue technology.I had following two lines of code and it was working properly.It returned "Connected Succesfully" message

queueManager =new MQQueueManager(QueueManagerName,channelName,connectionName);
strReturn = "Connected Successfully";

But after adding another line of code in between them it threw an exception saying "Error in the application"

queueManager = new MQQueueManager(QueueManagerName,channelName,connectionName);
queueManager.Connect();  // <-- added this line
strReturn = "Connected Successfully";

I'm pretty sure that the connection details are ok because it connects.but i cant connect to the queue.Can anyone help me.

有帮助吗?

解决方案

This is how you should do it:

System.String line = "This is a test message embedded in the MQTest01 program.";
int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;

try
{
   MQQueueManager _qMgr = new MQQueueManager(qManager);
   System.Console.Out.WriteLine("MQTest01 successfully connected to " + qManager);

   MQQueue queue = _qMgr.AccessQueue(outputQName, openOptions, null, null, null);
   System.Console.Out.WriteLine("MQTest01 successfully opened " + outputQName);

   MQPutMessageOptions pmo = new MQPutMessageOptions();

   MQMessage sendmsg = new MQMessage();
   sendmsg.Format = MQC.MQFMT_STRING;
   sendmsg.Feedback = MQC.MQFB_NONE;
   sendmsg.MessageType = MQC.MQMT_DATAGRAM;
   sendmsg.MessageId = MQC.MQMI_NONE;
   sendmsg.CorrelationId = MQC.MQCI_NONE;
   sendmsg.WriteString(line);

   // put the message on the queue
   queue.Put(sendmsg, pmo);
   System.Console.Out.WriteLine("Message Data>>>" + line);

   queue.Close();
   System.Console.Out.WriteLine("MQTest01 closed: " + outputQName);
   _qMgr.Disconnect();
   System.Console.Out.WriteLine("MQTest01 disconnected from " + qManager);
}
catch (MQException mqex)
{
   System.Console.Out.WriteLine("MQTest01 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
catch (System.IO.IOException ioex)
{
   System.Console.Out.WriteLine("MQTest01 ioex=" + ioex);
}

其他提示

There is no need to call anything other than the constructor to get connected to MQ Queue manager. The below line is good enough.

queueManager = new MQQueueManager(QueueManagerName,channelName,connectionName);

There is no Connect method in MQQueueManager .NET interface. I am wondering how your application compiled. Please look at the samples that are shipped with WebSphere MQ. You find them in \tools\dotnet\samples\cs\base.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top