2014-06-18 160 views
3

首先,我想道歉,因为我发现了很多类似问题的主题,但没有解决我的问题。ASP.net网站LocalDB部署到IIS7

我在Visual Studio 2012 Ultimate中开发了一个ASP.net网站(C#)。我创建了App_Data文件夹并创建了一个SQL Sever数据库。当所有的开发完成后,我决定将网站部署到Windows Server 2008 R2上的IIS7。部署之后,大多数网页都可以正常工作,除了那些包含数据库数据的网页。

我选择在IIS中的.NET Framework版本V4.0到

这是访问与例如一个GridView的页面时,我得到的错误。

Server Error in '/' Application. 

The system cannot find the file specified 
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: The system cannot find the file specified 

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): The system cannot find the file specified] 
[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.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +414 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196 
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146 
    System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16 
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94 
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110 
    System.Data.SqlClient.SqlConnection.Open() +96 
    System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121 
    System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +160 
    System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +108 
    dsNotificaTableAdapters.pessoasEnvolvidasTableAdapter.getPessoasEnvolvidas() +101 
    notificar.fillrblPessoas() +41 
    notificar.Page_Load(Object sender, EventArgs e) +327 
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 
    System.Web.UI.Control.OnLoad(EventArgs e) +92 
    System.Web.UI.Control.LoadRecursive() +54 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446 

感谢您的帮助提前!

+0

如何连接到您的数据库?它位于哪里?你发布的网站是否正确指向它?此错误听起来像发布的网站无法找到您的数据库... –

+0

嗨@DylanCorriveau,数据库位于App_Data网站文件夹内。 webconfig文件包含以下内容: Sota

回答

2

[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.)]

的LocalDB (里面的App_Data SQL数据库)主要用于开发和测试仅目的。当您发布到产品时,它不会与您的源代码一起被复制。

当您的应用程序开始运行时,您需要一个真正的SQL Server。因此,您需要将SQL Server安装在托管应用程序的相同服务器或专用SQL服务器中。然后附加该数据库。

+0

Hi @Win,我在Windows Server 2008 R2上安装了SQL Server 2014 Express。我使用sqlcmd命令行连接了我的数据库。服务SQL Server,SQL Server浏览器和SQL Server VSS编写器正在运行。你能否给我提供进一步的帮助来完成这项任务?谢谢。 – Sota

+0

确保您可以使用SSMS手动连接到SQL Server。如果是这样,那么更新应用程序web.config中的[连接字符串](http://www.connectionstrings.com/sql-server/)。如果您无法使用SSMS连接到SQL Server,那么您需要[排除故障](http://social.technet.microsoft.com/wiki/contents/articles/2102.how-to-troubleshoot-connecting-to- -sql-server-database-engine.aspx)*(许多问题已经在SO中被问到关于这个问题)*。 – Win

+0

我看不到提供的错误消息描述了你写的东西(即“App_Data中的SQL数据库仅用于开发/测试目的”)。如果只说没有找到LcoalDB文件。 –

1

LocalDB仍然必须安装在计算机上以使其工作,它不是免费版本的SQL Server,它会自动包含在您的应用程序部署中。在本地工作站上,安装Visual Studio时安装了LocalDB。

因此,最终还是需要运行应用程序的服务器可以连接到的数据库服务器。 LocalDB旨在被开发人员在本地使用,因此在服务器情况下,您可能需要查看SQL Server Express。

0

您需要设置的应用程序池的配置值,以使您的网站,以达到您.mdf文件:

在C:\ WINDOWS \ SYSTEM32 \ INETSRV \设置\的applicationHost.config

集etProfileEnvironment = “真”这样的:

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

https://blogs.msdn.microsoft.com/sqlexpress/2011/12/08/using-localdb-with-full-iis-part-1-user-profile/