Issue when deploying an ASP.NET MVC + LocalDB application

Serge picture Serge · Dec 9, 2013 · Viewed 15k times · Source

I have deployed my ASP.NET MVC 5 application on a server but it crashes on every page using the localdb.

Yet I copied the App_Data folder where the .mdf file is located. And I even installed SQL Server 2012 Express on the machine.

Nevertheless every time I get the same error.

Le fichier spécifié est introuvable
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: Le fichier spécifié est introuvable

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): Le fichier spécifié est introuvable]
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352431

Sorry, a part of it s in french despite I set the ui to us-english.

The web.config file looks like this:

<connectionStrings>
   <add name="ConnectionString" 
        connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=C:\inetpub\wwwroot\MygLogWeb\App_Data\Database.mdf;Integrated Security=True" 
        providerName="System.Data.SqlClient"/>
</connectionStrings>

And it was like this before:

<add name="ConnectionString" 
     connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>

Answer

Mr. B picture Mr. B · Dec 9, 2013

That's because LocalDb is not intended for production use.

See article: Creating an Entity Framework Data Model for an ASP.NET MVC Application

Specifically, this text from the article: "Typically SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it is not designed to work with IIS."

So change your connectionString value to use a real sql server database and you should be good to go!