【问题标题】:Local IIS cannot connect to LocalDB本地 IIS 无法连接到 LocalDB
【发布时间】:2017-02-22 03:22:12
【问题描述】:

我几乎不想问这个问题,因为这个问题似乎有很多变体,但到目前为止没有任何帮助。

我正在尝试支持几年前运行良好的旧 ASP.Net 2.0 应用程序(不同的计算机/环境。)我可以毫无问题地显示默认/主页。但是,所有数据库调用都会失败。我可以通过 SSMS 连接到“(localdb)\MSSQLLocalDB”(使用 Windows 身份验证或预期的应用程序凭据。)选择语句通过 SSMS 在所有表/视图/sprocs 上运行而没有问题(到目前为止都是空的,但它们存在.)

例外

Server Error in '/' Application.
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: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.)
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.Data.SqlClient.SqlException: 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: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.)

Source Error:

Line 64:     SqlDataAdapter da =  new SqlDataAdapter(sql, connection);
Line 65:     DataSet ds = new DataSet();
Line 66:     da.Fill(ds);

Source File: c:\{snip}\Page.aspx.cs    Line: 66

Stack Trace:
[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: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.
)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4876207
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +354
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +367
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +225
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +431
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +31
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +112
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94
   ExportProgress.Page_Load(Object sender, EventArgs e) in c:\Users\qamain\Desktop\IDC\code\web\InstructionalDays\ExportProgress.aspx.cs:66
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.5420; ASP.NET Version:2.0.50727.5459 

连接字符串

<connectionStrings>
    <add name="ConnStr" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyApp;User ID=MyUser;Password=****" providerName="System.Data.SqlClient"/>
</connectionStrings>

环境 Win7 Pro VM、ASP.Net 2.0、SQL 上的管理员帐户(各种,见下图)

通过 VS 2015 社区调试

我确保 .Open 语句确实得到了预期的连接字符串。

已验证的数据库信息

C:\Users\myuser>sqllocaldb info mssqllocaldb
Name:               mssqllocaldb
Version:            12.0.2000.8
Shared name:
Owner:              MYVM\myuser
Auto-create:        Yes
State:              Running
Last start time:    2/22/2017 1:33:53 AM
Instance pipe name: np:\\.\pipe\LOCALDB#E36AA52B\tsql\query

通过 SQL Server 2016 配置管理器进行 SQL 设置

IIS 身份验证设置

这些指定的“myuser”与 SQL DB 的所有者相同

事件日志

这些是单次尝试点击页面/数据库的事件。警告与本文顶部列出的消息/异常相同。 SQL错误(不太有用)重复了五次(如下。)

故障排除步骤

  1. 已删除并重新创建 DB
  2. 删除了以下路径项, C:\Users\myuser\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances
  3. 禁用防火墙以确保不是问题
  4. 回收/重新启动应用程序池和网站(多次)
  5. 在此文件中将loadUserProfilesetProfileEnvironment 设置为true,C:\Windows\System32\inetsrv\config\applicationHost.config 如所指示的here

我到底错过了什么?

【问题讨论】:

    标签: asp.net sql-server iis


    【解决方案1】:

    如果值得保留,我会将其留给社区。​​p>

    问题现在已经解决了,很遗憾,我不知道究竟是哪一步解决了问题。

    我最近确实注意到,通过 sqllocaldb.exe 删除和重新创建 MSSQLLocalDB 条目会丢弃对应用程序所需数据库的访问(以及它的表/视图/等)。这很奇怪,因为当我尝试重新创建它时,SQL抱怨 db.mdf 文件已经在 C:\Users\myser 文件夹中。我在那里删除了 MDF 和 LDF 文件,然后重新创建了 db(包含的用户、表、视图、sproc),一切终于可以正常工作了。

    呃,几天后工作。如果社区认为这篇文章无关紧要,请不要冒犯(但也许对其他人来说,收集故障排除步骤可能是值得的。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      相关资源
      最近更新 更多