1
votes

Currently I am trying to connect to a queue manager using C++ in a Linux machine, and MQCONNX function, making use of MQCD structure to set server, channel, transport type, etc. Once compiled and run, I get a 2058 reason code (Queue Manager Name error).

I am using the following code:

extern "C" {
#include <cmqc.h>
#include <cmqxc.h>
}
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main ( int argc, char * * argv ) {
    printf( "TESTING QUEUE MANAGER CONNECTION\n" );
    
    MQHCONN sourceConnectionHandle;    
    MQLONG completionCode = 0;
    MQLONG reasonCode = 0;
    MQCD connectionDescriptor = {MQCD_CLIENT_CONN_DEFAULT};
    connectionDescriptor.TransportType = MQXPT_TCP;
    strcpy(connectionDescriptor.ChannelName, "DEV.APP.SVRCONN");
    strcpy(connectionDescriptor.ConnectionName,"mqprimary(1414)");
    
    MQCNO connectionOptions = {MQCNO_DEFAULT};  
    connectionOptions.ClientConnPtr = &connectionDescriptor;
    
    MQCONNX(" ", &connectionOptions, &sourceConnectionHandle, &completionCode, &reasonCode);
    
    if(MQCC_OK != completionCode)
    {            
        printf("MQCONNX ended with reason code %d connecting to source queue manager.\n", reasonCode);
    }
    else
    {       
        printf ("Connected to Source Queue Manager.\n");
    }
}

I have tried to connect to the queue manager with setenv and MQCONN as follow, without using MQCD structure, and it worked fine, but I need to do this using MQCONNX and MQCD:

setenv("MQSERVER","DEV.APP.SVRCONN/TCP/mqprimary(1414)",1);
MQCONN(" ", &sourceConnectionHandle, &completionCode, &reasonCode);

Any idea why a 2058 reason code is being returned using MQCONNX?

Thanks in advance for your help.

1

1 Answers

3
votes

The MQCD was added to version 2 of the MQCNO structure. You need to set connectionOptions.Version = MQCNO_VERSION_2 (or higher if you want to use additional fields of the CNO)