c# - 将 LocalDB 部署到 IIS7 的 ASP.net 网站

标签 c# asp.net .net sql-server

首先,我想道歉,因为我发现了很多类似问题的主题,但没有一个解决我的问题。

我在 Visual Studio 2012 Ultimate 中开发了一个 ASP.net 网站 (C#)。我创建了 App_Data 文件夹并创建了一个 SQL Server 数据库。当所有开发完成后,我决定将网站部署到 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 

提前感谢您的帮助!

最佳答案

[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 服务器上。然后附加该数据库。

关于c# - 将 LocalDB 部署到 IIS7 的 ASP.net 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24291532/

相关文章:

c# - C# 中的最佳 "not is"语法

asp.net - SharePoint 自定义当前导航/PortalSiteMapProvider

.net - WIX:从日志文件中删除属性

.net - 为什么我的 .Net 应用程序会联系 Verisign?

c# - DataGrid过滤,多输入,MVVM,C#

c# - 适用于 C/C++/C# 的免费静态代码扫描器

c# - 在 GDI+ 中绘制带渐变的折线

javascript - 如何在 JavaScript 中从 GridView 获取值

c# - 需要在 C# 中使用字符串从数据库中查找 ID 号

.net - Powershell和.NET表单对象