The queue does not exist or you do not have sufficient permissions to perform the operation. exception while sending message via MSMQ

前端 未结 1 1139
生来不讨喜
生来不讨喜 2021-01-06 08:01

I have created a function to send message via MSMQ but getting exception while executing. below is my function.

public void SendMessageToQueue(ChessQueue che         


        
相关标签:
1条回答
  • 2021-01-06 08:17
    if (!MessageQueue.Exists(".\\Private$\\" + chessQueue.QueueName))
    {
        queue = new MessageQueue(".\\Private$\\chessqueue");
        // etc..
    

    There are two bugs in this code. First problem is that it hard-codes the queue name in the string instead of using chessQueue.QueueName. A mismatch will be fatal of course. Second problem, and surely the most critical one, is that it doesn't actually create the queue. Proper code should resemble:

    string name = ".\\Private$\\" + chessQueue.QueueName;
    if (!MessageQueue.Exists(name))
    {
        queue = MessageQueue.Create(name);
        // etc...
    

    Looked like this after I ran this code, with one queue.Send() call:

    enter image description here

    0 讨论(0)
提交回复
热议问题