[英]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上的环境管理员帐户(多种,请参见下图)
通过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设置
IIS身份验证设置
事件日志
这些是单次尝试访问页面/数据库的事件。 该警告与本文顶部列出的消息/例外相同。 SQL错误(不太有用)将重复五次(如下所示)。
故障排除步骤
C:\\Users\\myuser\\AppData\\Local\\Microsoft\\Microsoft SQL Server Local DB\\Instances
loadUserProfile
和setProfileEnvironment
为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.