|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
C#, .Close() and Error Code 2018 |
« View previous topic :: View next topic » |
Author |
Message
|
KirTakat |
Posted: Mon Jul 25, 2005 7:39 am Post subject: C#, .Close() and Error Code 2018 |
|
|
Newbie
Joined: 22 Jul 2005 Posts: 6
|
I have an issue with the .Net implementation of MQ when I try and close out a queue. If I have an MQQueue named queue, and I'm done with it, I'll check to see if it's not NULL, and if it's currently Open. If both of those are true, I call queue.Close(), but many times when I call this, it will throw an error code 2018.
Any idea what I'm doing wrong?
Here's the code in question:
Code: |
if(queue != null && queue.OpenStatus)
queue.Close();
|
|
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jul 25, 2005 7:49 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Well, first off,
Messages wrote: |
2018 (X'07E2')MQRC_HCONN_ERROR
Explanation:
The connection handle Hconn is not valid, for one of the following reasons:
The parameter pointer is not valid, or (for the MQCONN or MQCONNX call) points to read-only storage. (It is not always possible to detect parameter pointers that are not valid; if not detected, unpredictable results occur.)
The value specified was not returned by a preceding MQCONN or MQCONNX call.
The value specified has been made invalid by a preceding MQDISC call.
The handle is a shared handle that has been made invalid by another thread issuing the MQDISC call.
The handle is a shared handle that is being used on the MQBEGIN call (only nonshared handles are valid on MQBEGIN).
The handle is a nonshared handle that is being used a thread that did not create the handle.
The call was issued in the MTS environment in a situation where the handle is not valid (for example, passing the handle between processes or packages; note that passing the handle between library packages is supported).
Completion Code:
MQCC_FAILED
Programmer Response:
Ensure that a successful MQCONN or MQCONNX call is performed for the queue manager, and that an MQDISC call has not already been performed for it. Ensure that the handle is being used within its valid scope (see the description of MQCONN in the WebSphere MQ Application Programming Guide).
On z/OS, also check that the application has been linked with the correct stub; this is CSQCSTUB for CICS applications, CSQBSTUB for batch applications, and CSQQSTUB for IMS applications. Also, the stub used must not belong to a release of the queue manager that is more recent than the release on which the application will run.
|
Most likely, you are running into either of these two
Quote: |
The handle is a nonshared handle that is being used a thread that did not create the handle.
The call was issued in the MTS environment in a situation where the handle is not valid (for example, passing the handle between processes or packages; note that passing the handle between library packages is supported). |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
KirTakat |
Posted: Mon Jul 25, 2005 8:13 am Post subject: |
|
|
Newbie
Joined: 22 Jul 2005 Posts: 6
|
There's no passing of the handle at all, all of this takes place within a single function. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jul 25, 2005 8:15 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
KirTakat wrote: |
There's no passing of the handle at all, all of this takes place within a single function. |
Then maybe you are misusing the handle somehow.
Also, it's not usually a good idea to have a complete Connect,Open, Put/Get,Close, Disconnect in the same function - as it implies that you are doing all operations as a unit of work and many times over. This is not very efficient. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
KirTakat |
Posted: Mon Jul 25, 2005 8:29 am Post subject: |
|
|
Newbie
Joined: 22 Jul 2005 Posts: 6
|
Before I forget, thanks for your help, now then:
Quote: |
it's not usually a good idea to have a complete Connect,Open, Put/Get,Close, Disconnect in the same function |
Your point about efficency is definately valid, but I'm not the one who designed this in the first place, and I'm fairly certain I don't have leave to rewrite it however I like
As to the function itself, I'll explain what it's doing, then you can tell me if it's a horrible way to go about it:
Essentially this is a small thread that monitors the status of a queue to make sure that a different application is picking up messages in a timely manner. So every 5 minutes or so, this application connects to the queue, checks what's on it, then disconnects. Then it sleeps for 5 minutes. The issue is that sometimes when it disconnects, it throws that error, and I'm not really sure why. [/quote] |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jul 25, 2005 8:58 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
KirTakat wrote: |
Your point about efficency is definately valid, but I'm not the one who designed this in the first place, and I'm fairly certain I don't have leave to rewrite it however I like |
You're not rewriting it. You're refactoring it. You do not need to remove any code, you do not need to change any code. You merely need to wrap different pieces in different functions, and add a couple of calls to the right function in the right place.
So, where your program might now look like
main:
Loop
call MQ checker
sleep 5
end loop
end main
MQ Checker:
connect
open
inquire/get/put
close
disconnect
end MQ Checker
It could - and again, you aren't deleting or changing any existing code here, now look like
main:
call Connect
Loop
call MQ Checker
sleep 5
end loop
disconnect
end main
MQ Checker:
open
inquire/get/put
close
end MQ checker
It'll be a lot better performing, and your 2018s may go away.
KirTakat wrote: |
As to the function itself, I'll explain what it's doing, then you can tell me if it's a horrible way to go about it: |
If you need to examine the contents of the message to determine if the other program is working, this is about the only way to do it. _________________ I am *not* the model of the modern major general. |
|
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
|
|
|
|