2013-12-09 115 views
1

我已经在服务器上部署了ASP.NET MVC 5应用程序,但它在每个使用localdb的页面上都崩溃了。部署ASP.NET MVC + LocalDB应用程序时出现问题

但是我复制了.mdf文件所在的App_Data文件夹。我甚至在机器上安装了SQL Server 2012 Express。

不过每次我得到相同的错误。

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

对不起,尽管我将ui设置为英文,但其中的一部分仍然以法语显示。

web.config文件看起来是这样的:

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

而正是这样才:

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

回答

4

这是因为的LocalDB不用于生产用途。

参见文章:Creating an Entity Framework Data Model for an ASP.NET MVC Application

具体来说,从文章这样的文字:“通常不用于生产的Web应用程序的SQL Server Express的LocalDB尤其不建议使用Web应用程序的生产使用,因为它不是。旨在与IIS协同工作。“

所以改变你的connectionString值来使用真正的sql server数据库,你应该很好去!

+2

那么LocalDB有什么好处呢? – Serge

+1

快速发展。测试。很像Visual Studio可以根据需要启动一个新的Web服务器,而不是强迫您首先设置IIS以查看您的应用程序运行。 –

+0

如果您使用生产数据库,该怎么办? –

1

我有同样的问题,并在这里(Is it normal to use LocalDb in production?)解决方案成立。 @Krzysztof Kozielczyk @提供2篇文章:firstsecond。 来自第一个技巧就足以解决我的问题。
其实我只是加入到C:\ WINDOWS \ SYSTEM32 \ INETSRV \设置\的applicationHost.config

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

顺便说一句,我的连接字符串看起来像你的第二个(用 “| DataDirectory目录| \ Database.mdf”) 。