随机 SQL 连接问题。工作,然后不工作,然后工作,然后 BAM!再也不会工作了?

Posted

技术标签:

【中文标题】随机 SQL 连接问题。工作,然后不工作,然后工作,然后 BAM!再也不会工作了?【英文标题】:Random SQL connection issues. Works, then doesn't work, then works, then BAM! Never works again? 【发布时间】:2011-11-13 15:35:51 【问题描述】:

我在这里使用 WebMatrix,并且有一个数据库,它一切正常,直到它随机向我抛出一个关于连接字符串不存在的错误。这总是不时发生,我假设这是 WebMatrix 中的一个错误,它只是忘记或丢失某处的设置,因为它与我所做的任何更改无关。

这是错误,以及堆栈跟踪:(为这么长的错误道歉)

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: 26 - Error Locating Server/Instance Specified) 
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: 26 - Error Locating Server/Instance Specified)

Source Error: 


Line 1:  @
Line 2:     WebSecurity.InitializeDatabaseConnection("SV", "UserProfile", "UserId", "Email", true);
Line 3:      WebMail.SmtpServer = "mail.sv.com";
Line 4:      WebMail.EnableSsl = false;


Source File: d:\HostingSpaces\svisible\sv.com\wwwroot\_AppStart.cshtml    Line: 2 

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: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +270
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   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) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   WebMatrix.Data.Database.EnsureConnectionOpen() +44
   WebMatrix.Data.<QueryInternal>d__0.MoveNext() +71
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +4232308
   WebMatrix.Data.Database.QuerySingle(String commandText, Object[] args) +103
   WebMatrix.WebData.SimpleMembershipProvider.CheckTableExists(Database db, String tableName) +59
   WebMatrix.WebData.SimpleMembershipProvider.CreateTablesIfNeeded() +55
   WebMatrix.WebData.WebSecurity.InitializeMembershipProvider(SimpleMembershipProvider sMembership, DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean createTables) +73
   WebMatrix.WebData.WebSecurity.InitializeProviders(DatabaseConnectionInfo connect, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
   WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String connectionStringName, String userTableName, String userIdColumn, String userNameColumn, Boolean autoCreateTables) +51
   ASP._Page__AppStart_cshtml.Execute() in d:\HostingSpaces\svisible\sv.com\wwwroot\_AppStart.cshtml:2
   System.Web.WebPages.ApplicationStartPage.<ExecuteInternal>b__3() +65
   System.Web.WebPages.ApplicationStartPage.<GetSafeExecuteStartPageThunk>b__a(Action action) +7
   System.Web.WebPages.ApplicationStartPage.ExecuteInternal() +78
   System.Web.WebPages.ApplicationStartPage.ExecuteStartPageInternal(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +202
   System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +41

[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
   System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +88
   System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +287
   System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +113
   System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application) +71
   System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +217
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +517
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237 

为什么 WebMatrix 一直这样对我?有人可以帮我解决这个问题吗?我无休止地搜索,发现了很多相关的页面,但无法正常工作。

谢谢

【问题讨论】:

您是否监控 SQL SErver 本身的错误?也许问题不在应用层,而在数据库层 这不是 webmatrix,你只是有一个到数据库服务器的 flakey 连接。错误不是说连接字符串不存在而是说它无法连接到数据库。 嗯,改变了吗?我正在尝试为您的 cmets +1,但没有选择。 好吧,我不知道要找什么 - 一切正常,我可以从 Navicat 访问数据库,并从另一个网站执行查询/插入,也是在 webmatrix 中制作的。 错误说你有某种网络问题,你能确保应用程序和数据库之间的网络连接稳定吗? 【参考方案1】:

检查并确保在您的 Web 服务器和 SQL Server 上都禁用了 TCP Chimney。 http://technet.microsoft.com/en-us/library/gg162682(WS.10).aspx

【讨论】:

对近两年前的一个项目随机投反对票,没有任何解释?

以上是关于随机 SQL 连接问题。工作,然后不工作,然后工作,然后 BAM!再也不会工作了?的主要内容,如果未能解决你的问题,请参考以下文章

将 SQL Server 凭据添加到 ADO 连接

与我的代码不一致,它似乎在随机场合工作

在 VBA 中使用 SQL 连接两个 Excel 工作簿中的数据(只读错误)

水壶 '?'不工作表输入步骤

PHP SQL Server连接工作或不工作[重复]

SQL SERVER 工作日记--删除执行计划