0

I am busy with C# MQ, i want to add text on the Q, but not sure if what i am doing is wrong. Getting the following error.

An unhandled exception of type 'System.NullReferenceException' occurred in Data.Manager.dll, this happens at "Put1Queue.Put(myPutMessage, Put1PutMsgOptions);"

Here is the code:

class Program
{

    static void Main(string[] args)
    {
        MQ mq = new MQ();
        Console.Read();
    }
}

public class MQ
{

    private MQQueue queue;
    private MQMessage queueMessage;
    private MQQueueManager queueManager;

    private string queueManagerName;
    private string host;
    private int port;
    private string channel;
    private string queueName;

    public String putMsg;
    public String markerMsg;
    private MQQueueManager Put1QueueManager;
    private MQPutMessageOptions Put1PutMsgOptions;
    private MQQueue Put1Queue;

    private MQQueueManager Put2QueueManager;
    private MQPutMessageOptions Put2PutMsgOptions;
    private MQQueue Put2Queue;

    private MQQueueManager myQueueManager;
    private MQPutMessageOptions myPutMsgOptions;
    private MQQueue myQueue;

    private Hashtable queueProperties;

    public MQ()
    {
        setupTestData();

    }

    public void setupTestData()
    {

        markerMsg = "<msglamdav5_xml><system message_id=\"\" message_type=\"\" correlation_id=\"\" date_time_stamp=\"\" originator=\"\" destination=\"\" queue_manager=\"\" txn_req_number=\"\" txn_req_id=\"\"/><security user_name=\"G9022O2 \" user_type=\"\" user_identity=\"G90226K     \" user_language=\"\" environment=\"PPEX    \" host_name=\"\"/><errors/><data><txn_ctl bus_txn_phase=\"3\" bus_txn_session_id=\"\" /><data_key party_no=\"0\"/><tasks><task txn_id=\"MARK<uniqueNum> \" event_type=\"2\" external_txn_id=\"04255841252012-06-22-04.56.14.960000            \"><task_data><servicedata inputdata=\"0124473471\"/></task_data><task_metadata><lists/></task_metadata></task></tasks></data></msglamdav5_xml>";

        try { 
        // Setup connection information
        MQEnvironment.Hostname = "SLHUBQ2.sanlam.co.za";
        MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
        MQEnvironment.properties.Add(MQC.CCSID_PROPERTY, 437);
        MQEnvironment.Channel = "CLIENTS";//"EFL.SRVCONN";
        MQEnvironment.Port = 1615;//lr.eval_int("<Port>");


        Put1QueueManager = new MQQueueManager("SLHUBQ2");
        int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;

        Put1Queue = Put1QueueManager.AccessQueue("LAMDA.PERF.REQUEST", openOptions, null, null, null);

        Put1PutMsgOptions = new MQPutMessageOptions();

        Put1PutMsgOptions.Options = MQC.MQPMO_NEW_MSG_ID | MQC.MQPMO_NEW_CORREL_ID;

        }
        catch (Exception error)
        {

        }

        try {
                MQMessage myPutMessage = new MQMessage();
                myPutMessage.ClearMessage();
                myPutMessage.Persistence = MQC.MQPER_PERSISTENT;
                myPutMessage.Persistence = MQC.MQPER_NOT_PERSISTENT;
                myPutMessage.CorrelationId = MQC.MQCI_NONE;
                myPutMessage.MessageId  = MQC.MQMI_NONE;

                myPutMessage.Format = MQC.MQFMT_STRING; 
                myPutMessage.ReplyToQueueName= "LAMDA.PERF.RESPONSE";

                myPutMessage.WriteString(markerMsg);


              Put1Queue.Put(myPutMessage, Put1PutMsgOptions);




        }
        catch (MQException error)
        {


        }


        try
        {
            Put1Queue.Close();
            Put1QueueManager.Disconnect();

        }
        catch (Exception error)
        {

        }



    }



    }
}
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65

2 Answers2

1

The problem might be in your code line

Put1Queue = Put1QueueManager.AccessQueue("LAMDA.PERF.REQUEST", openOptions, null, null, null);

Probably 'AccessQueue' method returns 'null' result. So what you can try to check:

  1. Is your queue name is correct.
  2. Are the options correct. You may try to pass MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING options.
Renatas M.
  • 11,694
  • 1
  • 43
  • 62
0

How about you print out the exceptions in EVERY catch statement because I bet you are getting RC 2035 on the AccessQueue, hence, Put1Queue is null for the Put method. i.e.

catch (MQException mqex)
{
   System.Console.Out.WriteLine("MQException cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
catch (System.IO.IOException ioex)
{
   System.Console.Out.WriteLine("IOException ioex=" + ioex);
}
catch (Exception ex)
{
   System.Console.Out.WriteLine("Exception ex=" + ex);
}
Roger
  • 7,062
  • 13
  • 20