尝试打开邮件队列时应用程序出错?

时间:2014-02-20 06:34:43

标签: .net message-queue ibm-mq

我是WebSphere Message Queue技术的新手。我有两行代码并且工作正常。它返回了"Connected Succesfully"消息

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

但是在他们之间添加了另一行代码之后,它抛出了一个例外"Error in the application"

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

我很确定连接细节是正确的,因为它连接。但我无法连接到队列。任何人都可以帮助我。

2 个答案:

答案 0 :(得分:3)

这是你应该怎么做的:

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);
}

答案 1 :(得分:2)

除了构造函数之外,没有必要调用连接到MQ Queue管理器的任何东西。以下行足够好。

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

MQQueueManager .NET接口中没有Connect方法。我想知道你的应用程序是如何编译的。请查看WebSphere MQ附带的示例。您可以在\ tools \ dotnet \ samples \ cs \ base中找到它们。