Getting MQ Exception: MQRC_NOT_AUTHORIZED, Reason Code: 2035 while getting list of Queues from IBM MQ using C# .net Core 8.0 Console Application

Ronak Padaliya 5 Reputation points
2025-04-11T07:39:06.19+00:00

I have installed IBM MQ and IBM MQ Explorer by using the below steps mention in the PDF file, IBM MQ Installation in windows.pdf

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();
		}
	}
}

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

Screenshot 2025-04-11 130651

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

#IBMMQ

Developer technologies | C#
0 comments No comments
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.