【问题标题】:ASP.net website with LocalDB deployment to IIS7将 LocalDB 部署到 IIS7 的 ASP.net 网站
【发布时间】:2014-06-18 17:18:23
【问题描述】:

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

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

提前感谢您的帮助!

【问题讨论】:

  • 你是如何连接到你的数据库的?它位于哪里?您发布的网站是否正确指向它?这个错误听起来像是发布的站点找不到您的数据库...
  • 嗨@DylanCorriveau,数据库位于App_Data 上的网站文件夹内。 webconfig 文件具有以下内容:

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


【解决方案1】:

[SqlException (0x80131904): 网络相关或实例特定 建立与 SQL Server 的连接时出错。这 服务器未找到或无法访问。验证实例 名称正确且 SQL Server 配置为允许远程 连接。 (提供者:SQL 网络接口,错误:52 - 无法 找到本地数据库运行时安装。验证 SQL Server Express 已正确安装并且本地数据库运行时 功能已启用。)]

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

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

【讨论】:

  • 嗨@Win,我已经在我的 Windows Server 2008 R2 上安装了 SQL Server 2014 Express。我已经使用 sqlcmd 命令行附加了我的数据库。 SQL Server、SQL Server Browser 和 SQL Server VSS Writer 服务正在运行。您能否为我提供进一步的帮助以完成此任务?谢谢。
  • 确保您可以使用 SSMS 手动连接到 SQL Server。如果是这样,则更新应用程序 web.config 中的connection string。如果您无法使用 SSMS 连接到 SQL Server,那么您需要 troubleshoot the problem(SO 中已针对该问题提出了很多问题)
  • 我看不到提供的错误消息描述了您所写的内容(即“App_Data 中的 SQL 数据库仅用于开发/测试目的。”)。如果只说没有找到 LcoalDB 文件。
  • @AlexG.P.我只是在解释 LocalDB 主要用于开发和测试目的。当您发布到生产环境时,它不会与您的源代码一起复制。理想情况下,它不应该在生产环境中使用。如果您有问题,请创建一个新的;我很乐意为您提供帮助。
【解决方案2】:

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

所以最后,您仍然需要一个数据库服务器,运行您的应用程序的服务器可以连接到该服务器。 LocalDB 旨在供开发人员在本地使用,因此在服务器情况下,您可能需要查看 SQL Server Express。

【讨论】:

    【解决方案3】:

    您需要在 appPool 配置中设置一个值,以使您的网站能够访问您的 .mdf 文件:

    在 C:\Windows\System32\inetsrv\config\applicationHost.config 中

    像这样设置 etProfileEnvironment="true":

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多