Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message Queue Exception : Queue does not exist or you do not have sufficient permissions to perform the operation

At this line of code i am getting the error as i mentioned

I declared MSMQ_NAME as string as follows

  private const string MSMQ_NAME = ".\\private$\\ASPNETService";

    private void DoSomeMSMQStuff()
    {
        using (MessageQueue queue = new MessageQueue(MSMQ_NAME))
        {
            queue.Send(DateTime.Now); //Exception raises
            queue.Close();
        }
    }

enter image description here

enter image description here

like image 420
Developer Avatar asked May 02 '11 08:05

Developer


4 Answers

Can you first verify the queue is existing with the name 'ASPNETService' at below location?

Computer Management -> Services and Applications -> Message Queuing -> Private Queues

like image 116
somatic rev Avatar answered Sep 28 '22 12:09

somatic rev


For others struggling with this and pulling their hair out like I have been, I finally found something that works when all of the upvoted suggestions failed.

Even if you think the host name of your target queue's hosting system is being resolved correctly, don't believe it. Try replacing the host name with an IP address and see if it works. It does for me. I can WRITE to a public queue using a host name on my remote server without problems, but trying to READ from it produces exactly the error listed for this question.

For example, if I declare the following:

private static string QueueName = @"FormatName:DIRECT=TCP:SOMEHOST\MyQueue";
private static System.Messaging.MessageQueue Queue = new System.Messaging.MessageQueue(QueueName);

Where "MyQueue" is a public queue on server SOMEHOST, the following code will successfully insert messages to the queue, but always fails on the Receive():

            Queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });

        // The Receive() call here is a blocking call.  We'll wait if there is no message in the queue, and processing
        // is halted until there IS a message in the queue.
        //
        try
        {
            Queue.Send("hello world", System.Messaging.MessageQueueTransactionType.Single);

            var msg = Queue.Receive(MessageQueueTransactionType.Single);

        }
        catch (Exception ex)
        {
            // todo error handling
        }

One simple change in how I specify the queue location is all that's needed to make the Receive() stop failing with the dreaded "queue does not exist or you do not have sufficient permissions" error:

private static string QueueName = @"FormatName:DIRECT=TCP:192.168.1.100\MyQueue";

(Obviously I've obfuscated IP addresses and other sensitive info). Using the IP address is not obviously a production-worthy scenario, but it did point me to some type of name resolution problem as being the possible cause of the error. I cannot explain why Send() works but Receive() does not when I am using a host name instead of IP, but I can reproduce these results consistently. Until I can figure out what's going on with the name resolution, I'm no longer wasting a day trying to read messages from a queue.

like image 33
markaaronky Avatar answered Sep 28 '22 12:09

markaaronky


I had a similar problem. I was confused because my code worked on my local development machine, but not in production. Even stranger, the queues were created the exact same way.

It turns out that IIS doesn't have access to them by default. I just opened up the permissions.

Computer Management -> Private Queues -> right-click queue name -> Properties -> Security Tab -> click "Everyone" user -> click Full Control/Allow checkbox -> click OK

This fixed it for me, and in my case it's not an issue, but you may want to think about the ramifications of just opening it up for all users.

Also, I had to do this across all queues on all servers. There doesn't seem to be a way to multi-select queues or folders in order to set permissions for multiple queues simultaneously.

like image 22
digarok Avatar answered Sep 28 '22 12:09

digarok


I was having the same problem.

I had created a new private queue and gave Full Permission to Everyone.

But I was still catching a "Queue does not exist or you do not have sufficient permissions to perform the operation" when trying to Send() to the queue. And I was able to verify that MessageQueue.Exists(".\\private$\\myqueue") was returning true.

Restarting the Message Queuing Service resolved my the problem for me.

like image 40
Dave Baghdanov Avatar answered Sep 28 '22 11:09

Dave Baghdanov