DEV Community

Ronak Padaliya
Ronak Padaliya

Posted on

Getting MQ Exception: MQRC_NOT_AUTHORIZED

I have installed IBM MQ and IBM MQ Explorer by using the below steps mentioned in the PDF file,

After that, I want to access the queues list from a C# console app (.NET Core 8.0) as below,

`using IBM.WMQ;
using IBM.WMQ.PCF;
using System.Collections;

namespace IBM_MQ_Testing
{
public class Program
{
public static void Main(string[] args)
{
string queueManagerName = "QManager01";

        Hashtable connectionProperties = new Hashtable
        {
            { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED },
            { MQC.CHANNEL_PROPERTY, "SYSTEM.DEF.SVRCONN" },
            { MQC.HOST_NAME_PROPERTY, "YOUR-PC-NAME" }, // Or your machine name or IP
            { MQC.PORT_PROPERTY, 1414 },
        };

        try
        {
            MQQueueManager queueManager = new MQQueueManager(queueManagerName, connectionProperties);
            Console.WriteLine($"Connected to Queue Manager: {queueManager.Name}");

            // Create PCF message agent
            IBM.WMQ.PCF.MQCFH header = new IBM.WMQ.PCF.MQCFH(IBM.WMQ.PCF.CMQCFC.MQCFC_LAST, IBM.WMQ.PCF.CMQCFC.MQCMD_INQUIRE_Q_NAMES);
            IBM.WMQ.PCF.PCFMessageAgent agent = new IBM.WMQ.PCF.PCFMessageAgent(queueManager);

            // Create PCF request
            IBM.WMQ.PCF.PCFMessage request = new IBM.WMQ.PCF.PCFMessage(IBM.WMQ.PCF.CMQCFC.MQCMD_INQUIRE_Q_NAMES);
            request.AddParameter(MQC.MQCA_Q_NAME, "*"); // Wildcard for all queues

            // Send PCF request
            IBM.WMQ.PCF.PCFMessage[] responses = agent.Send(request);

            foreach (IBM.WMQ.PCF.PCFMessage response in responses)
            {
                string[] queueNames = (string[])response.GetParameterValue(MQC.MQCACF_Q_NAMES);
                foreach (var name in queueNames)
                {
                    Console.WriteLine("Queue: " + name.Trim());
                }
            }

            queueManager.Disconnect();
        }
        catch (MQException mqe)
        {
            Console.WriteLine($"MQ Exception: {mqe.Message}, Reason Code: {mqe.ReasonCode}");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }

        Console.ReadLine();
    }
}
Enter fullscreen mode Exit fullscreen mode

}`

But when I run the above console app from Visual Studio 2022 in ADMINISTRATION mode, it throws the following error,

Image description

I don't know what's wrong with it. It's great to give any ideas or suggestions that work. 😊

Top comments (0)