Using RavenDB with Azure websites

In a previous post I explored various options of hosting RavenDB. While using RavenDB as a Windows Service or hosted in IIS is probably the best way to go in most cases there are a number of cases where the embedded option is great. And one of the places where I really like the embedded option of hosting RavenDB is when doing simple standalone websites. And with the new Azure website option that is a great way to host them.


The code is real straightforward and just like before. I am using a DataDirectory option when creating the EmbeddableDocumentStore here but that does the same thing as I did before using the connection string.

   1: public static DocumentStore DocumentStore { get; private set; }


   3: private void CreateRavenDB()

   4: {

   5:     DocumentStore = new EmbeddableDocumentStore()

   6:     {

   7:         DataDirectory = @"~\App_Data\db"

   8:     };

   9:     DocumentStore.Initialize();

  10: }


RavenDB Configuration

The example code from my previous blog posts will just work except for one gotcha. By default RavenDB will search for a post to use by itself. However that means scanning the available posts and that isn’t permitted by default. The result is an exception:

System.Net.NetworkInformation.NetworkInformationException: Access is denied


With a stack trace like this:

[NetworkInformationException (0x5): Access is denied]
   System.Net.NetworkInformation.SystemIPGlobalProperties.GetAllTcpConnections() +1570717
   System.Net.NetworkInformation.SystemIPGlobalProperties.GetActiveTcpListeners() +74
   Raven.Database.Util.PortUtil.FindPort() +79
   Raven.Database.Util.PortUtil.GetPort(String portStr) +133
   Raven.Database.Config.InMemoryRavenConfiguration.Initialize() +4355
   Raven.Database.Config.RavenConfiguration.LoadConfigurationAndInitialize(IEnumerable`1 values) +307
   Raven.Database.Config.RavenConfiguration..ctor() +196
   Raven.Client.Embedded.EmbeddableDocumentStore.get_Configuration() +87
   Raven.Client.Embedded.EmbeddableDocumentStore.set_DataDirectory(String value) +40
   MvcApplication3.MvcApplication.CreateRavenDB() +57
   MvcApplication3.MvcApplication.Application_Start() +169


The fix is simple. Instead of letting RavenDB search for a port by itself just specify one in the web.config. The setting required is "Raven/Port".

   1: <configuration>

   2:   <appSettings>

   3:     <add key="Raven/Port"

   4:          value="9090"/>

   5:     ....

   6:   </appSettings>

   7: ....

That is all there is to it 🙂


Want to see for yourself?

I have a simple page using RavenDB as the backend store hosted on Azure right here.



One thought on “Using RavenDB with Azure websites

  1. Great post, Maurice. I expected a lot more hassle to be able to do this (in fact, I came across your article doing a quick search while I was waiting for VS to fire when I sat down to try it). Thanks for sharing; I’ll let you know how I get on.

Leave a Reply

Your email address will not be published. Required fields are marked *