2017-02-22 132 views
0

我幾乎不想問這個問題,因爲這個問題似乎有很多變種,但是迄今沒有任何幫助。本地IIS無法連接到LocalDB

我想站起來幾年前運行良好的舊ASP.Net 2.0應用程序(不同的計算機/環境)。我可以顯示沒有問題的默認/主頁面。但是,所有數據庫調用失敗。我可以通過SSMS連接到「(localdb)\ MSSQLLocalDB」(使用Windows身份驗證或預期的應用程序憑證)。Select語句通過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上臨VM,ASP.Net 2.管理員帳戶,SQL(不同,見下圖) Installed SQL bits, 2012-2016

調試通過VS 2015年社區

我保證了。開說法確實得到預期連接字符串。

驗證數據庫信息

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設置通過SQL服務器2016配置管理器

TCP/IP protocol enabled

IIS驗證設置

這些指定相同的「myuser的」原樣的SQL數據庫 IIS account auth passes and same as SQL owner

事件日誌

店主這些都是從單一的企圖撞頁/ DB的事件。警告與本帖頂部列出的消息/例外相同。 SQL錯誤(不太有用)會重複五次(如下所示。) enter image description here

故障排除步驟

  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

在地球上有我錯過了什麼?

回答

0

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

現在問題已解決,不幸的是,我不知道究竟哪個步驟解決了問題。

我最近才注意到,通過sqllocaldb.exe刪除並重新創建MSSQLLocalDB條目,從而刪除了所需的應用程序數據庫(以及它的tables/views/etc)。這很奇怪,因爲當我試圖重新創建它時, SQL抱怨db.mdf文件已經在C:\Users\myser文件夾中。我在那裏刪除了MDF和LDF文件,然後重新創建了數據庫(包含用戶,表格,視圖,sproc),並且所有這些都最終正常工作。

呃,稍後幾天的工作。如果社區覺得這篇文章是無關緊要的(但也許收集的故障排除步驟對其他人來說可能是值得的),那麼不要冒犯。