![](/img/trans.png)
[英]Public Message Queue Exception : Message Queue Exception : Queue does not exist or you do not have sufficient permissions to perform the operation
[英]Message Queue Exception : Queue does not exist or you do not have sufficient permissions to perform the operation
在這行代碼中,我收到了我提到的錯誤
我將 MSMQ_NAME 聲明為字符串,如下所示
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();
}
}
您可以先驗證隊列是否存在,名稱為“ASPNETService”,位於以下位置?
計算機管理 -> 服務和應用程序 -> 消息隊列 -> 私有隊列
我有一個類似的問題。 我很困惑,因為我的代碼可以在本地開發機器上運行,但不能在生產環境中運行。 更奇怪的是,隊列的創建方式完全相同。
事實證明 IIS 默認情況下無法訪問它們。 我剛剛打開了權限。
計算機管理->專用隊列->右鍵單擊隊列名稱->屬性->安全選項卡->單擊“每個人”用戶->單擊完全控制/允許復選框->單擊確定
這為我解決了問題,在我的情況下這不是問題,但您可能想考慮為所有用戶開放它的后果。
此外,我必須在所有服務器上的所有隊列中執行此操作。 似乎沒有一種方法可以多選隊列或文件夾以同時為多個隊列設置權限。
我遇到了同樣的問題,我已經使用以下 class 創建隊列來解決它
private MessageQueue messageQueue;
public const string DEFAULT_QUEUE_NAME = "newQueue";
public const string QUEUENAME_PREFIX = ".\\Private$\\";
public static string QueueName
{
get
{
string result = string.Format("{0}{1}", QUEUENAME_PREFIX, DEFAULT_QUEUE_NAME);
return result;
}
}
public void SendMessage()
{
string queuePath = QueueName;
MessageQueue messageQueue = MessageQueue.Create(queuePath);
messageQueue.Send("msg");
}
以相同的方式創建消息隊列以接收消息。
我遇到了同樣的問題。
我創建了一個新的私人隊列,並為每個人提供了完全權限。
但是在嘗試將Send()
到隊列時,我仍然遇到“隊列不存在或您沒有足夠的權限來執行操作”。 而且我能夠驗證MessageQueue.Exists(".\\private$\\myqueue")
正在返回true
。
重新啟動消息隊列服務為我解決了問題。
我遇到了同樣的問題,我確實喜歡在下面檢查隊列是否存在。 如果是,則發送消息,否則創建隊列然后發送消息
MessageQueue msgQueue = null;
string queuePath = ".\\Private$\\billpay";
Payment newPayment = new Payment()
{
Payee = txtPayee.Text,
Payor = txtPayor.Text,
Amount = Convert.ToInt32(txtAmount.Text),
DueDate = dpDueDate.SelectedDate.Value.ToShortDateString()
};
Message msg = new Message();
msg.Body = newPayment;
msg.Label = "Gopala - Learning Message Queue";
if (MessageQueue.Exists(queuePath) == false)
{
//Queue doesnot exist so create it
msgQueue = MessageQueue.Create(queuePath);
}
else
{
msgQueue = new MessageQueue(queuePath);
}
msgQueue.Send(msg);
對於其他為此苦苦掙扎並像我一樣拔掉頭發的人,當所有贊成的建議都失敗時,我終於找到了可行的方法。
即使您認為目標隊列的托管系統的主機名被正確解析,也不要相信。 嘗試用 IP 地址替換主機名,看看它是否有效。 它對我有用。 我可以毫無問題地使用遠程服務器上的主機名寫入公共隊列,但嘗試從中讀取會產生針對此問題列出的錯誤。
例如,如果我聲明以下內容:
private static string QueueName = @"FormatName:DIRECT=TCP:SOMEHOST\MyQueue";
private static System.Messaging.MessageQueue Queue = new System.Messaging.MessageQueue(QueueName);
其中“MyQueue”是服務器 SOMEHOST 上的公共隊列,以下代碼將成功地將消息插入隊列,但在 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
}
我指定隊列位置的一個簡單更改就是使 Receive() 停止失敗並出現可怕的“隊列不存在或您沒有足夠的權限”錯誤:
private static string QueueName = @"FormatName:DIRECT=TCP:192.168.1.100\MyQueue";
(顯然我混淆了 IP 地址和其他敏感信息)。 使用 IP 地址顯然不是一個值得生產的方案,但它確實指出某種類型的名稱解析問題可能是導致錯誤的原因。 當我使用主機名而不是 IP 時,我無法解釋為什么 Send() 有效但 Receive() 無效,但我可以始終如一地重現這些結果。 在我弄清楚名稱解析發生了什么之前,我不再浪費一天時間嘗試從隊列中讀取消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.