ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexGeneral IBM MQ Supportmqrc 2018 error while call is made to remote mq using MQOPEN

Post new topicReply to topic
mqrc 2018 error while call is made to remote mq using MQOPEN View previous topic :: View next topic
Author Message
ganeshfriends2
PostPosted: Tue Aug 21, 2018 5:48 am Post subject: mqrc 2018 error while call is made to remote mq using MQOPEN Reply with quote

Newbie

Joined: 21 Aug 2018
Posts: 3

Hi,

I am trying to connect Remote MQ using C language , While connecting to MQ i am using MQCONNX and MQOPEN methods , After execution of MQOPEN method it returns an error MQRC 2018.
Below is the code for reference .
Also want to know is there any kind of authentication problem or server level problem causing this.
Thanks

Code:
 int MS_MQ_Open(const char *chr_p_qmname, const char *chr_p_qname, const char *mode, MQHCONN *Hcon, MQHOBJ *Hobj, INTL_ENV_DATA_STRUCT_H *p_intlenv_data_struct_h,
                                   DEBUG_INFO_STRUCT_H **l_debug_info_ptr)
    {
        MQOD     od = {MQOD_DEFAULT};    /* Object Descriptor             */
        MQLONG   OpenCode;               /* MQOPEN completion code        */
       MQLONG   O_options;
       MQLONG   Reason;
       MQLONG   CReason;
       MQLONG    CompCode;   
       MQCNO mqcno = {MQCNO_DEFAULT} ; /* Connection options */
       MQCD mqcd = {MQCD_CLIENT_CONN_DEFAULT}; /* Channel Defs */
       MQCSP csp = {MQCSP_DEFAULT};
       MQCHAR   chr_l_qmname[MQ_Q_MGR_NAME_LENGTH];
       char userId[50];
       char password[50];
           strncpy(userId,"XXXXXX",50);
          strncpy(chr_l_qmname, chr_p_qmname, MQ_Q_MGR_NAME_LENGTH);
          strncpy(mqcd.ConnectionName, "10.000.00.00(port number)", MQ_CONN_NAME_LENGTH);
          strncpy(mqcd.ChannelName,"SVRCONN",MQ_CHANNEL_NAME_LENGTH);
           mqcno.SecurityParmsPtr = &csp;
          mqcno.Version = MQCNO_VERSION_5;
          csp.AuthenticationType = MQCSP_AUTH_USER_ID_AND_PWD;
           csp.CSPUserIdPtr = userId;
          csp.CSPUserIdOffset = 0;
           csp.CSPUserIdLength = strlen(userId);
           strncpy(password,"XXXX",50);
           csp.CSPPasswordPtr = password;
          csp.CSPPasswordOffset = 0;
           csp.CSPPasswordLength = strlen(password);
          mqcno.ClientConnPtr = &mqcd;
          mqcno.Version = MQCNO_VERSION_5;
          
       MQCONNX(chr_l_qmname,&mqcno, &Hcon, &CompCode,&CReason);
       if (CompCode == MQCC_FAILED) {
         printf("MQCONNX ended with reason code |%ld|\n", CReason);
       }
     strncpy(od.ObjectName, chr_p_qname, (size_t)MQ_Q_NAME_LENGTH);
       if(!strcmp(mode, "I"))
       {
          O_options = MQOO_INQUIRE + MQOO_FAIL_IF_QUIESCING;
       }
       else if (!strcmp(mode, "O"))
       {
          O_options =   MQOO_OUTPUT                    /* open queue for output        */
          + MQOO_FAIL_IF_QUIESCING + MQOO_SET_ALL_CONTEXT; /* but not if MQM stopping      */
       }
       else
       {
          printf("Invalid mode %s\n", mode);
          APL_GOBACK_FAIL
       }
       MQOPEN(Hcon, &od, O_options, &Hobj, &OpenCode, &Reason);
       if (Reason != MQRC_NONE) {
         printf("MQOPEN ended with reason code |%ld|\n", Reason);
       }
    }
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Aug 21, 2018 7:26 am Post subject: Re: mqrc 2018 error while call is made to remote mq using MQ Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25311
Location: Ohio, USA

ganeshfriends2 wrote:
Also want to know is there any kind of authentication problem or server level problem causing this.


No - that would be one of 2063, 2035, , 2059, 2019 or 2009 depending on the exact problem.

2018 is specific to an invalid connection object.

Does your code work if you use MQCONN instead? For testing purposes?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
markt
PostPosted: Tue Aug 21, 2018 8:10 am Post subject: Reply with quote

Chevalier

Joined: 14 May 2002
Posts: 404

Look at your levels of pointer indirection on the Hcon variable.
Back to top
View user's profile Send private message
ganeshfriends2
PostPosted: Tue Aug 21, 2018 11:00 pm Post subject: Re: mqrc 2018 error while call is made to remote mq using MQ Reply with quote

Newbie

Joined: 21 Aug 2018
Posts: 3

Vitor wrote:
ganeshfriends2 wrote:
Also want to know is there any kind of authentication problem or server level problem causing this.


No - that would be one of 2063, 2035, , 2059, 2019 or 2009 depending on the exact problem.

2018 is specific to an invalid connection object.

Does your code work if you use MQCONN instead? For testing purposes?


Hi , Thanks for your reply , Yes you are right code works perfectly if i use MQCONN to connect local MQ , But i want to connect to remote MQ and it is creating problem .
Back to top
View user's profile Send private message
tczielke
PostPosted: Wed Aug 22, 2018 4:06 am Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 747
Location: Illinois, USA

Your Hcon variable is not defined correctly.

It should be defined as follows:

MQHCONN Hcon;

This resolves to a signed 4 byte integer if you inspect the cmqc.h file.

You have your Hcon defined as follows:

MQHCONN *HCon;

which resolves to a pointer. This could be a 4 byte or 8 byte pointer, based on your program which could be causing your 2018 error. Regardless, you need to define your Hcon correctly. Also, I would just define it as a variable in your method and not as an input that you just overwrite anyway.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Aug 22, 2018 4:41 am Post subject: Re: mqrc 2018 error while call is made to remote mq using MQ Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25311
Location: Ohio, USA

ganeshfriends2 wrote:
Hi , Thanks for your reply , Yes you are right code works perfectly if i use MQCONN to connect local MQ , But i want to connect to remote MQ and it is creating problem .


Does it work if you use MQCONN to connect to the remote queue manager?

The only difference is that MQCONNX allows more information to be passed; it returns the same connection object which is at issue.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Wed Aug 22, 2018 4:57 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1900
Location: Melbourne, Australia

Code:
int MS_MQ_Open(const char *chr_p_qmname, const char *chr_p_qname, const char *mode, MQHCONN *Hcon, MQHOBJ *Hobj, INTL_ENV_DATA_STRUCT_H *p_intlenv_data_struct_h, DEBUG_INFO_STRUCT_H **l_debug_info_ptr)

This states that HCon is a pointer to a MQHCONN and Hobj is a pointer to a MQHOBJ. In normal MQI programming, HCon and Hobj are usually the variable names for the actual data structures, not pointers to them.

I suggest changing HCon to pHCon and Hobj to pHobj. The 'p' prefix makes the code easier to understand and maintain.

The call to MQCONN then has argument pHCon:
Code:
MQCONNX(chr_l_qmname,&mqcno, pHcon, &CompCode,&CReason);


Code the call to MQOPEN like this:
Code:
MQOPEN( *pHcon, &od, O_options, pHobj, &OpenCode, &Reason);

The *pHcon gets the value of MQHCONN, which is what MQOPEN expects.
pHobj is the address of MQHOBJ, which is what MQOPEN expects, so that it can set its value.

Please check your call to MS_MQ_Open(). It should contain &Hcon and &Hobj, to pass the address of the data (if declared as MQHCONN HCon; MQHOBJ Hobj; )

Does that all make sense?
_________________
Glenn
Back to top
View user's profile Send private message
tczielke
PostPosted: Wed Aug 22, 2018 6:14 pm Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 747
Location: Illinois, USA

I would recommend the OP reviews a sample like amqsput0.c. hcon is an MQHCONN which is just a signed 4 byte integer like int if 64 bit. You pass in the address of hcon (i.e. &hcon) into the MQCONNX and then the hcon variable itself (i.e. hcon) for the subsequent API calls like MQOPEN. It looks like the OP is running into an issue when the hcon which was declared as a pointer is passed into the MQOPEN call which is expecting a 4 byte signed integer for the hcon input. If the pointer is an 8 byte pointer, the hcon data that MQ set in the hcon pointer variable during the MQCONNX call is probably being misrepresented in the movement from an 8 byte pointer to a 4 byte signed integer.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Thu Aug 23, 2018 4:15 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1900
Location: Melbourne, Australia

tczielke wrote:
I would recommend the OP reviews a sample like amqsput0.c ...

The MQ C language samples have the MQI calls coded in the main line, rather than inside functions, so they do not illustrate how pointers to MQ structures are handled with function calls. If a programmer does not have a 100% understanding of C pointers, they will inevitably get it wrong, with strange an unexpected results. I still do this sometimes.
_________________
Glenn
Back to top
View user's profile Send private message
tczielke
PostPosted: Thu Aug 23, 2018 5:42 pm Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 747
Location: Illinois, USA

If the programmer's intention here is to truly pass in a pointer to an MQHCONN in the MS_MQ_OPEN input so that the caller of this method can track the derived hcon, then that is doable. However, you would then want to pass the hcon variable itself (i.e. hcon) into the MQCONNX and then dereference the pointer (e.g. *hcon) on the MQOPEN call. And of course, you need to set the MQHCONN * hcon appropriately on the call to the MS_MQ_OPEN function, so it does have a valid pointer to an MQHCONN.

ganeshfriends2 - Is that what you were trying to do?
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
ganeshfriends2
PostPosted: Thu Aug 30, 2018 4:07 am Post subject: Reply with quote

Newbie

Joined: 21 Aug 2018
Posts: 3

tczielke wrote:
If the programmer's intention here is to truly pass in a pointer to an MQHCONN in the MS_MQ_OPEN input so that the caller of this method can track the derived hcon, then that is doable. However, you would then want to pass the hcon variable itself (i.e. hcon) into the MQCONNX and then dereference the pointer (e.g. *hcon) on the MQOPEN call. And of course, you need to set the MQHCONN * hcon appropriately on the call to the MS_MQ_OPEN function, so it does have a valid pointer to an MQHCONN.

ganeshfriends2 - Is that what you were trying to do?


Yes , I am actually passing the Hcon as pointer because i m using the same in other functions , Thanks for your help....[/quote]
Back to top
View user's profile Send private message
tczielke
PostPosted: Thu Aug 30, 2018 4:19 am Post subject: Reply with quote

Shaman

Joined: 08 Jul 2010
Posts: 747
Location: Illinois, USA

You are welcome!

Here are a few other things to think about:

1) Your MS_MQ_Open function still makes an MQOPEN call with the Hcon, even if the previous MQCONNX call had failed.

2) How will the caller of this MS_MQ_Open function know that the Hcon was not derived correctly because the MQCONNX call failed?

3) Does your MQ client application have reconnection logic (and with some reasonable delay between failed connection attempts) if the MQ connection breaks at some point (e.g. queue manager is recycled, network blip, etc.). This is a requirement (connection recovery) that I have all our MQ client programmers meet for their MQ client applications.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Thu Aug 30, 2018 3:36 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1900
Location: Melbourne, Australia

tczielke wrote:
You are welcome!
Here are a few other things to think about:
1) Your MS_MQ_Open function still makes an MQOPEN call with the Hcon, even if the previous MQCONNX call had failed.
2) How will the caller of this MS_MQ_Open function know that the Hcon was not derived correctly because the MQCONNX call failed?
3) Does your MQ client application have reconnection logic (and with some reasonable delay between failed connection attempts) if the MQ connection breaks at some point (e.g. queue manager is recycled, network blip, etc.). This is a requirement (connection recovery) that I have all our MQ client programmers meet for their MQ client applications.

Yeah, the function return int should indicate success / failure. If MQCONNX fails, the function should immediately return (and not do the MQOPEN).

MQOO_SET_ALL_CONTEXT is a high authority. Does the app really need to override the defaults that MQ sets for context fields in the MQMD?
_________________
Glenn
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexGeneral IBM MQ Supportmqrc 2018 error while call is made to remote mq using MQOPEN
Jump to:



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
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.