Why is my MVC 5 application trying to access Local DB

912 views Asked by At

I have been developing an MVC 5 application on my local machine, and having just tried to public a test version to Azure, I have found this new error. My connection strings have no reference to a LocalDB, and I can't find anything in my code that wants to create or access a LocalDB. Yet I am receiving an error related to an attempt to create/access localDB:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory

Originally the project had forms authentication, but I later changed to AspNetIdentity framework. I'm concerned I've got some residue from the initial template with forms authentication that I cannot find despite combing the application several times and googling at length.

Here are the connection strings. There are no others. At least using a find function in Visual studio to look for "connectionString" - this is all:

<add name="elmah" connectionString="Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx" providerName="System.Data.SqlClient" />
<add name="IdentityDbContext" connectionString="Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx" providerName="System.Data.SqlClient" />
<add name="ORLODbContext" connectionString="metadata=res://*/ORLODbContext.csdl|res://*/ORLODbContext.ssdl|res://*/ORLODbContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:xxxxx.database.windows.net,1433;Initial Catalog=xxxxx;User ID=xxxxx@xxxxx;Password=xxxxx&quot;" providerName="System.Data.EntityClient" />

My googling has led me to add these other features to the web.config. In the system.web:

<authentication mode="None" />
<membership>
  <providers>
    <clear />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
  </providers>
</profile>

Here, my googling also suggests I should add:

<roleManager>
  <providers>
    <clear />
  </providers>
</roleManager>

But if I do this, I get the error:

Default Role Provider could not be found.

Seeing as I don't want one, it seems, I thought maybe I don't need this bit. But please correct me if I'm wrong.

Is there anything else I should look at?

1

There are 1 answers

1
DavidG On BEST ANSWER

Asp.Net by default uses the role manager, even when working with Identity. The solution is to disable it completely. In your web.config remove the entire roleManager section and replace it with:

<roleManager enabled="false" />

For some further info, in your machine.config you likely have a line like this:

<add name="AspNetSqlRoleProvider"
    connectionStringName="LocalSqlServer" applicationName="/" type="..."/>

And a connection string like this:

<add name="LocalSqlServer" 
    connectionString="...localdb..." 
    providerName="System.Data.SqlClient"/>

So leaving the role manager entries in there make Asp.Net start looking in this local db before your IdentityDbContext. Removing the entries means it tries to fine an entry and fails. So the only solution is to disable it completely.