Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDb on Azure Websites - Access Denied

I'm playing around with the new Websites feature on Azure and trying to get an MVC site running with RavenDB in embedded mode. Everything works fine locally but running the deployed site in azure I get this error:

System.Net.NetworkInformation.NetworkInformationException: Access is denied

This happens when I create the db instance in global.asax:

Store = EmbeddableDocumentStore { ConnectionStringName = "RavenDb" };

My connection string is:

<add name="RavenDb" connectionString="DataDir=~\App_Data\Raven" />

Thanks!

like image 833
Joel Mitchell Avatar asked Jul 17 '12 19:07

Joel Mitchell


1 Answers

When a port is not specified for RavenDb it will go out and attempt to find it's own, it does this by calling IPGlobalProperties.GetActiveTcpListeners().

RavenDb | PortUtil.cs

var activeTcpListeners = IPGlobalProperties
                         .GetIPGlobalProperties()
                         .GetActiveTcpListeners();

Calling GetActiveTcpListeners() intern calls the Win32 function GetTcpTable() which attempts to enumerate all of the possible port combinations on the host. For obvious reasons, it would not be a good scenario to allow folks to do port scanning within Windows Azure Web Sites. Which means the GetTcpTable operation fails and when something fails in the world of development we throw an exception.

In this particular case the exception is a NetworkInformationException which is raised do to the security permissions neglecting the call to GetTcpTable. This is why it results in an Access Denied message.

tl;dr

Add a default port to your web.config appsettings section:

 <appSettings> 
    <add key="Raven/Port" value="*"/> <!-- Add real tcp port # -->
    <add key="Raven/DataDir" value="~\Data"/> 
    <add key="Raven/AnonymousAccess" value="Get" /> 
 </appSettings> 
like image 105
cory-fowler Avatar answered Sep 18 '22 11:09

cory-fowler