2014-06-18 216 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/