How do I Change Where MSMQ Messages are Stored or Persisted?

Posted by: Steven Smith, on 18 Jan 2011 | View original | Bookmarked: 0 time(s)

If you are using MSMQ, either directly or with the help of a package like NServiceBus, you may encounter errors if your server becomes overloaded with messages either due to high load or as a result of a failure in your message handling process.  If this happens, you may see exceptions like this one (ask me how I know this):

System.Messaging.MessageQueueException (0x80004005): Insufficient resources to perform operation. at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType) at NServiceBus.Unicast.Transport.Msmq.MsmqTransport.Send(TransportMessage m, String destination) in d:\BuildAgent-01\work\20b5f701adefe8f8\src\impl\unicast\NServiceBus.Unicast.Msmq\MsmqTransport.cs:line 346 at NServiceBus.Unicast.UnicastBus.SendMessage(IEnumerable'1 destinations, String correlationId, MessageIntentEnum messageIntent, IMessage[] messages) in d:\BuildAgent-01\work\20b5f701adefe8f8\src\unicast\NServiceBus.Unicast\UnicastBus.cs:line 593 at NServiceBus.Unicast.UnicastBus.SendMessage(String destination, String correlationId, MessageIntentEnum messageIntent, IMessage[] messages) in d:\BuildAgent-01\work\20b5f701adefe8f8\src\unicast\NServiceBus.Unicast\UnicastBus.cs:line 559 at NServiceBus.Unicast.UnicastBus.NServiceBus.IBus.Send(IMessage[] messages) in d:\BuildAgent-01\work\20b5f701adefe8f8\src\unicast\NServiceBus.Unicast\UnicastBus.cs:line 518

The Insufficient resources to perform operation MessageQueueException means just what it says the computer is out of resources.  In my case, the issue was disk space.

The problem in this case was that the C drive on the server in question had filled up with messages (nearly 1 million of them, each with a fair bit of data).  The default location for MSMQ messages is in c:\windows\system32\msmq\storage, assuming that your queue is set up to be persistent, and not just in memory.  If you want to change this location to a non-system drive, which I would strongly recommend, you can do so fairly easily through the MSMQ user interface.  Of course, you may not know where the MSMQ user interface is, or even how to view MSMQ messages and queues, in which case, read this

Once youre at the MSMQ user interface, simply right-click on the Message Queuing item in the treeview, and select properties.


Next, select the Storage tab, and choose whatever new location you like for the files.  I recommend putting all three in the same folder on a data drive.


Theres unfortunately no way to script this action, and if you have services that depend on message queueing, they will be restarted as part of this process (or it will try to, anyway).  When you change the options on the storage tab, it takes the following actions:

  • Checks that the location is valid (a local disk with correct file system, etc)
  • Creates the necessary directory structure
  • Sets permissions
  • Moves the data to the new location

You can read more details about how this works and why you have to perform these actions through the UI, rather than scripting them, here.

In my own situation, I moved things to D:\msmq\storage, and I found that if I created this folder structure first, then the folder permissions were not set correctly and the message queueing service could not restart.  If instead I only created the d:\msmq folder and still set the folder in the UIs textboxes to d:\msmq\storage, then MSMQ successfully created the storage folder and did everything else correctly.  Might have just been a fluke in my case, but if you run into problems, give that a shot.

Category: .NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 2784 | Hits: 1

Similar Posts

  • Oredev Wrap-Up more
  • MSDN Guidance on ASP.NET MVC vs WebForms and its Impact on my EF + ASP.NET Work more
  • What needed to be monitored to get better Governance more
  • Adding users to a TFS project when youre not on the domain more
  • Assembly-Free jQuery in SharePoint Sites Using the SmartTools jQueryLoader more
  • N Tier Design Lessons Learned Part 1 more
  • Why not Classic (Legacy) ASP? more
  • The myth that TDD or test-first slows you down is true more
  • DotNetNuke 5.1.4 Released more
  • DotNetNuke 5.1.3 Released more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD