|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ C# 2018 Error |
« View previous topic :: View next topic » |
Author |
Message
|
robertjenkin |
Posted: Fri Nov 12, 2004 7:16 am Post subject: MQ C# 2018 Error |
|
|
Newbie
Joined: 12 Nov 2004 Posts: 2
|
Hello all..
I have a simple c# program to get messages from queue. I need to get messages from MQ within transaction so I am executing Begin and Commit methods to control the transaction. When ever I execute Begin I get an 2018 error. Without the Begin/Commit statements all works. Any ideas or hints would be greatly appreicated.
Following is the class code I am currently using.
public class MQInterface
{
private MQQueueManager mqQMgr;
private MQQueue mqQueue;
private MQGetMessageOptions mqGetMsgOpts;
private MQMessage mqMsg;
private bool bConnected = false;
private bool bTransaction = false;
public MQInterface() {}
public bool Connect(string mqQueueMgr, string mqQueueName, string mqChannel) {
// determine how to connect
string[] parts;
char[] separator = {'/'};
string channelname = "";
string transporttype = "";
string connectionname = "";
// connect to queue manager
try {
if (mqChannel.Length > 0) {
parts = mqChannel.Split(separator);
if (parts.Length>0) channelname = parts[0];
if (parts.Length>1) transporttype = parts[1];
if (parts.Length>2) connectionname = parts[2];
mqQMgr = new MQQueueManager(mqQueueMgr,channelname,connectionname);
} else {
if (mqQueueMgr.Length>0) {
mqQMgr = new MQQueueManager(mqQueueMgr);
} else {
mqQMgr = new MQQueueManager();
}
}
} catch (MQException ex) {
bConnected = false;
throw ex;
}
try {
mqQueue = mqQMgr.AccessQueue(mqQueueName,MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING);
} catch (MQException ex) {
bConnected = false;
throw ex;
}
mqGetMsgOpts = new MQGetMessageOptions();
mqGetMsgOpts.Options = MQC.MQGMO_WAIT;
mqGetMsgOpts.WaitInterval = 15 * 1000;
mqGetMsgOpts.MatchOptions = MQC.MQMO_NONE;
bConnected = true;
return (bConnected);
}
public void Disconnect() {
mqQueue.Close();
mqQMgr.Disconnect();
bTransaction = false;
bConnected = false;
}
public bool Begin() {
try {
mqQMgr.Begin();
bTransaction = true;
return (true);
} catch (MQException ex) {
throw ex;
}
}
public bool Commit() {
try {
mqQMgr.Commit();
bTransaction = false;
return (true);
} catch (MQException ex) {
throw ex;
}
}
public bool RollBack() {
try {
mqQMgr.Backout();
bTransaction = false;
return (true);
} catch (MQException ex) {
throw ex;
}
}
public bool Process(ref string sMessage) {
if (!bConnected) {
sMessage = "";
return (false);
}
try {
mqMsg = new MQMessage();
mqMsg.Format=MQC.MQFMT_STRING;
try {
mqQueue.Get(mqMsg, mqGetMsgOpts);
sMessage = mqMsg.ReadString(mqMsg.MessageLength);
} catch(MQException e) {
if (e.Reason == MQC.MQRC_NO_MSG_AVAILABLE) {
sMessage = "";
return (false);
} else {
throw e;
}
}
} catch(MQException e) {
throw e;
}
return (true);
}
} |
|
Back to top |
|
 |
robertjenkin |
Posted: Fri Nov 12, 2004 8:13 am Post subject: All ready resolved it.. |
|
|
Newbie
Joined: 12 Nov 2004 Posts: 2
|
The issue was caused by lack of sync point |
|
Back to top |
|
 |
kirani |
Posted: Fri Nov 12, 2004 10:55 am Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Also, you are using "Begin" keyword in your code. It's needed for doing 2-phase commit only. For local UOW you can use Syncpoint option. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|