我遇到了一个最奇怪的问题:当我编写一个新站点时,一切工作正常,而我正在工作的一个晚上突然站点无法再连接到 SQL Server。我可以使用 SQL Server Management Studio 愉快地连接,但该站点引发以下异常。
此机器上的防火墙已完全禁用。
一个问题是我让 SQL Server 在我创建的本地用户下运行。有时,当我重新启动 SQL Server 服务以查看是否可以解决问题时,该服务会抱怨登录失败。然后,我重新输入最初使服务运行的相同凭据,然后在再次说明该帐户已被授予登录作为服务权限后启动。但是,我尝试使用 NETWORK SERVICES 和 LOCAL SYSTEM,这两者都会从我的站点提示相同的异常。
但是,有时它确实有效。我在连接域的笔记本上运行它,所以我想知道这是否与我在家时无法与域交谈有关。然而,我创建的服务帐户是一个本地帐户。
我在 Windows 8 Enterprise 上的 IIS Express 上运行它(以防万一它是 Win8 的一些已知问题)。
添加Pooling=no
到连接字符串也没有效果。[参考]
这是我的连接字符串:Data Source=.;Initial Catalog=NotesBoard;Integrated Security=SSPI;
我还在“。”上使用了我的机器名称。以同样的结果。甚至尝试过 FQDN。
System.Web.HttpException 未被用户代码处理
HResult=-2147467259 消息=无法连接到 SQL Server 数据库。Source=System.Web ErrorCode=-2147467259 WebEventCode=0 StackTrace: 在 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) at System.Web.DataAccess.SqlConnectionHelper.EnsureDBFile(String connectionString) 在 System .Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) 在 System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) 在 WebMatrix.WebData.SimpleRoleProvider.GetRolesForUser(String username) 在 System.Web.Security.RolePrincipal。 IsInRole(String role) at ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:1 body) at System.Web.WebPages.WebPageBase.PopContext() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 续)
InnerException: System.Web.HttpException HResult=-2147467259 消息=无法连接到 SQL Server 数据库。Source=System.Web ErrorCode=-2147467259 WebEventCode=0 StackTrace: 在 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trust, String connectionString) at System.Web.Management.SqlServices.SetupApplicationServices (字符串服务器、字符串用户、字符串密码、布尔可信、字符串连接字符串、字符串数据库、字符串 dbFileName、SqlFeatures 功能、布尔安装)在 System.Web.Management.SqlServices.Install(字符串数据库,字符串 dbFileName,字符串连接字符串)在系统.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(字符串全文件名,String dataDir, String connectionString) InnerException: System.Data.SqlClient.SqlException HResult=-2146232060 消息=建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)Source=.Net SqlClient 数据提供者 ErrorCode=-2146232060 Class=20 LineNumber=0 Number=-1 Server="" State=0 StackTrace: at System .Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 次重试,DbConnectionOptions userOptions, DbConnectionInternal& connection)1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
在 System.Web.Management.SqlServices 的 System.Data.SqlClient.SqlConnection.Open() 处.GetSqlConnection(String server, String user, String password, Boolean trust, String connectionString) InnerException:
更新:这里 的新帖子中更清楚地定义了这个错误