簡體   English   中英

本地IIS無法連接到LocalDB

[英]Local IIS cannot connect to LocalDB

我幾乎不願問這個問題,因為這個問題似乎有很多變體,但到目前為止,沒有任何幫助。

我試圖站起一個舊的ASP.Net 2.0應用程序,該應用程序幾年前運行良好(在不同的計算機/環境中)。我可以顯示默認/主頁,而不會出現問題。 但是,所有數據庫調用均失敗。 我可以通過SSMS(使用Windows身份驗證或預期的應用程序憑據)通過SSMS連接到“(localdb)\\ MSSQLLocalDB”。Select語句通過SSMS在所有表/視圖/存儲過程上運行而沒有問題(因此,所有語句都是空的,但是它們存在。)

例外

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上的環境管理員帳戶(多種,請參見下圖) 已安裝的SQL位,2012-2016年

通過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 Configuration Manager進行SQL設置

啟用TCP / IP協議

IIS身份驗證設置

這些指定與SQL DB所有者相同的“ myuser” IIS帳戶身份驗證通過,與SQL所有者相同

事件日志

這些是單次嘗試訪問頁面/數據庫的事件。 該警告與本文頂部列出的消息/例外相同。 SQL錯誤(不太有用)將重復五次(如下所示)。 在此處輸入圖片說明

故障排除步驟

  1. 刪除並重新創建數據庫
  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所示這里

我到底錯過了什么?

如果值得保留,我將其留給社區。

現在,問題已解決,很遺憾,我不知道到底是哪一步解決了問題。

我最近才注意到,通過sqllocaldb.exe刪除並重新創建MSSQLLocalDB條目會刪除對所需應用程序數據庫的訪問(以及其表/視圖/等)。這很奇怪,因為當我嘗試重新創建它時,SQL抱怨說db.mdf文件已經在C:\\Users\\myser文件夾中。 我在那里刪除了MDF和LDF文件,然后重新創建了db(包含用戶,表,視圖,sproc),並且所有這些都終於可以工作了。

gh,幾天后的工作。 如果社區認為此帖子無關緊要,則不會冒犯(但其他人可能值得收集疑難解答步驟)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM