Issue when deploying an ASP.NET MVC + LocalDB application

久未见 提交于 2020-01-04 13:36:34

问题


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"/>

回答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!




回答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").



来源:https://stackoverflow.com/questions/20476608/issue-when-deploying-an-asp-net-mvc-localdb-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!