3

Actually, I have window service that read MSMQ queuw at an interval. My MSMQ queue is working without an issue but problem is when I stop or start windows service then it's throws an error. The complete error is given below:

**ERROR 65 DAL.MsmqImportListener - A MSMQ error occured
System.Messaging.MessageQueueException (0x80004005)
at System.Messaging.MessageQueue.AsynchronousRequest.End()
at DAL.MsmqImportListener.PeekCompleted(Object sender, PeekCompletedEventArgs e)**



private static void PeekCompleted(object sender, PeekCompletedEventArgs e)
    {
        var msmq = sender as MessageQueue;
        var messageProcessor = e.AsyncResult.AsyncState as MessageProcessorMethod;
        try
        {
            using (var scope = new TransactionScope())
            {
                msmq.EndPeek(e.AsyncResult);
                var message = msmq.ReceiveById(
                    e.Message.Id,
                    TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["MsmqReceiveTimeout"])),
                    MessageQueueTransactionType.Automatic);
                messageProcessor(message);
                scope.Complete();
            }
        }

        catch (MessageQueueException mqe)
        {
            // Check if timeout...no action if timeout, else log error
            if (mqe.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
            {
                Logger.Error("A MSMQ error occured", mqe);
                EmailDispatcher.SendInformationEmail("A MSMQ error occured" + Environment.NewLine + mqe);
            }
        }
        catch (Exception ex)
        {

            Logger.Error(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "An unexpected error was encountered, message with id {0} was put in error queue: {1}",
                    e.Message.Id,
                    success),
                ex);

        }
        finally
        {
            msmq.BeginPeek(TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["MsmqPeekTimeout"])), messageProcessor);
        }
    } 
leeand00
  • 25,510
  • 39
  • 140
  • 297
Arun Singh
  • 525
  • 2
  • 8
  • 20
  • Have you tried the answer from this thread http://stackoverflow.com/questions/6511865/messagequeueexception-0x80004005-access-to-message-queuing-system-is-denied – Jegan Jan 03 '17 at 11:12
  • Yes, I tried this solutions but not worked! my queue name is in small letter and i can't change queue name. – Arun Singh Jan 03 '17 at 11:14
  • Do you have access to the code? Would you be able to log the full stack trace to a log file? – Jegan Jan 03 '17 at 11:30
  • I have update the code but not have full stack trace – Arun Singh Jan 03 '17 at 11:54
  • Can you add 'Log' on each step, it is possible that the exception is not caught by your code. it could be failed cast the sender, or e; temporarily comment the 'if (mqe.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)' – Jegan Jan 03 '17 at 12:15
  • i have updated error description! you can check it going inside catch (MessageQueueException mqe) and do Logger.Error("A MSMQ error occured", mqe); – Arun Singh Jan 03 '17 at 12:21
  • Ah..., so the exception is thrown inside the 'using' statement, is it possible to add some log on each step to see values of 'e.AsyncResult, Id, MsmqReceiveTimeout' etc. Also add some log inside the messageProcessor method. – Jegan Jan 03 '17 at 12:39
  • i can't do more log in code because it's happening only on production not at AT/DEV/Stage etc. – Arun Singh Jan 04 '17 at 07:12

0 Answers0