Issue when deploying an ASP.NET MVC + LocalDB application

15,039

Solution 1

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!

Solution 2

I had the same issue and here (Is it normal to use LocalDb in production?) the solution founded. @Krzysztof Kozielczyk@ provides 2 articles: first and second. Tricks from the first was enough to resolve problem in my case.
Actually I just added to C:\Windows\System32\inetsrv\config\applicationHost.config

<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
     <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>

Btw, my connection string looks like your second one (with "|DataDirectory|\Database.mdf").

Share:
15,039
Serge
Author by

Serge

This place is getting ruined by people that think so high of themselves as sheriffs. Vote to close this profile if you think it's lacking a code sample.

Updated on June 05, 2022

Comments

  • Serge
    Serge almost 2 years

    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"/>
    
  • Mr. B
    Mr. B over 10 years
    Rapid development. Testing. Much like Visual Studio can spin up a new web server on demand rather than forcing you to setup IIS first just to see your app run.
  • Jason Foglia
    Jason Foglia about 10 years
    What if you are using production database's?