Daryl
Daryl

Reputation: 339

Error in application when try to open message queue?

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.

Upvotes: 1

Views: 181

Answers (2)

Roger
Roger

Reputation: 7506

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

Upvotes: 3

Shashi
Shashi

Reputation: 15283

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.

Upvotes: 2

Related Questions