队列不存在,或者您没有足够的权限来执行该操作。例外同时通过MSMQ发送消息 [英] The queue does not exist or you do not have sufficient permissions to perform the operation. exception while sending message via MSMQ

查看:2188
本文介绍了队列不存在,或者您没有足够的权限来执行该操作。例外同时通过MSMQ发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个功能,通过MSMQ,但得到的异常发送消息,同时执行。 下面是我的职责。

 公共无效SendMessageToQueue(ChessQueue chessQueue)
{
    MessageQueue队列= NULL;
    消息m = NULL;
    如果(!MessageQueue.Exists(\\私人$ \\+ chessQueue.QueueName))
    {
        队列=新MessageQueue(\\私人$ \\ chessqueue。);
        chessQueue.Messages =新的名单,其中,MessageObject>();
        chessQueue.Messages.Add(chessQueue.Message);
        queue.Formatter =新BinaryMessageFormatter();
        M =新的Message();
        m.Body = chessQueue;
    }
    其他
    {
        队列=新MessageQueue(\\私人$ \\+ chessQueue.QueueName);
        queue.Formatter =新BinaryMessageFormatter();
        米= queue.Receive();
        ChessQueue ExistingChessQueue = m.Body为ChessQueue;
        ExistingChessQueue.Messages.Add(chessQueue.Message);
        m.Body = ExistingChessQueue;
    }
    queue.Send(米);
    //获取异常,在这条线
}
 

例外: - 队列不存在,或者您没有足够的权限来执行该操作

另外我无法在计算机管理打开消息队列的安全选项卡。 见所附截图。

我试图手动创建属于私人消息队列和系统允许我这样做。见下文

以下是在MMC跨度。

解决方案

 如果(!MessageQueue.Exists(\\私人$ \\+ chessQueue.QueueName))
{
    队列=新MessageQueue(\\私人$ \\ chessqueue。);
    // 等等..
 

您在本code两个错误。第一个问题是,你硬codeD队列名称的字符串,而不是使用chessQueue.QueueName研究。不匹配将是致命的,当然。第二个问题,而且肯定是最关键的,就是你实际上并没有创建队列。正确的code应该类似于:

 字符串名称= + chessQueue.QueueName\\私人$ \\。
如果(!MessageQueue.Exists(名))
{
    队列= MessageQueue.Create(名称);
    // 等等...
 

这个样子后,我跑这code,有一个queue.Send()调用:

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

public void SendMessageToQueue(ChessQueue chessQueue)
{
    MessageQueue queue = null;
    Message m = null;
    if (!MessageQueue.Exists(".\\Private$\\" + chessQueue.QueueName))
    {
        queue = new MessageQueue(".\\Private$\\chessqueue");
        chessQueue.Messages = new List<MessageObject>();
        chessQueue.Messages.Add(chessQueue.Message);
        queue.Formatter = new BinaryMessageFormatter();
        m = new Message();
        m.Body = chessQueue;
    }
    else
    {
        queue = new MessageQueue(".\\Private$\\" + chessQueue.QueueName);
        queue.Formatter = new BinaryMessageFormatter();
        m = queue.Receive();
        ChessQueue ExistingChessQueue = m.Body as ChessQueue;
        ExistingChessQueue.Messages.Add(chessQueue.Message);
        m.Body = ExistingChessQueue;
    }            
    queue.Send(m);
    // Getting Exception at this Line
}

Exception:- The queue does not exist or you do not have sufficient permissions to perform the operation.

Also I'm unable to open security tab of Messaging Queue under Computer Management. See attached screenshot.

I tried creating the message queue under private manually and system allowed me to do so. See below

Below is the mmc span in.

解决方案

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

You have two bugs in this code. First problem is that you hard-coded 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 you didn'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:

这篇关于队列不存在,或者您没有足够的权限来执行该操作。例外同时通过MSMQ发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆