asp.net – 间歇性SQL连接错误
我有一个ASP.NET(Sitecore)应用程序,日志在我们客户的生产环境中显示间歇性的SQL连接错误.例外情况如下:
Exception: System.Data.SqlClient.SqlException Message: 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: Named Pipes Provider,error: 40 - Could not open a connection to SQL Server) Source: .Net SqlClient Data Provider at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,SqlCredential credential,Object providerInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,DbConnectionPool pool,String accessToken,Boolean applyTransientFaultHandling) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnection owningConnection,DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnection owningObject,DbConnectionOptions options,DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource`1 retry,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal oldConnection,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at Sitecore.Data.DataProviders.Sql.DataProviderCommand..ctor(IDbCommand command,DataProviderTransaction transaction,Boolean openConnection) at Sitecore.Data.DataProviders.Sql.SqlDataApi.<>c__DisplayClass4.<CreateCommand>b__3() at Sitecore.Data.DataProviders.NullRetryer.Execute[T](Func`1 action,Action recover) at Sitecore.Data.DataProviders.Sql.SqlDataApi.<>c__DisplayClass12.<CreateReader>b__10() at Sitecore.Data.DataProviders.NullRetryer.Execute[T](Func`1 action,Action recover) at Sitecore.Data.DataProviders.Sql.SqlDataApi.CreateReader(String sql,Object[] parameters) at Sitecore.Data.DataProviders.Sql.SqlDataApi.<CreateObjectReader>d__6`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at Sitecore.Eventing.EventQueue.ProcessEvents(Action`2 handler) at Sitecore.Eventing.EventProvider.RaiseQueuedEvents() Nested Exception Exception: System.ComponentModel.Win32Exception Message: The network path was not found 6420 16:53:53 ERROR Exception processing remote events from database: web Exception: System.Data.SqlClient.SqlException Message: 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: Named Pipes Provider,error: 40 - Could not open a connection to SQL Server) Source: .Net SqlClient Data Provider at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,Object[] parameters) at Sitecore.Data.DataProviders.Sql.SqlDataApi.<CreateObjectReader>d__6`1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source) at Sitecore.Eventing.EventQueue.ProcessEvents(Action`2 handler) at Sitecore.Eventing.EventProvider.RaiseQueuedEvents() Nested Exception Exception: System.ComponentModel.Win32Exception Message: The network path was not found 如果您提供的连接字符串无效,而您指定的服务器不存在或无法在网络上访问,则此错误是典型的.但是,该网站99%的时间都能正常运行. 在此示例中,错误来自Sitecore的RaiseQueuedEvents计划任务,但异常也是从其他各个地方引发的,包括在网站中点击URL时产生的http 500. 有趣的是它们是波浪形的,即在几秒钟的时间内可能有多达100个例外. 管理服务器的客户基础架构团队非常坚定地认为它不是网络问题,并且应用程序代码有问题,并且报告在这些异常似乎发生时数据库流量有所增加:
解决方法
它与Sitecore无关,但我之前看到过与另一个内容管理系统非常相似的情况.我也遇到了类似的挑战,基础设施工作人员确信数据库服务器很好,问题出在网站上.
我怀疑网络问题,所以我的方法是: >我写了一个SQL脚本,可以从命令行运行,并显示相同的连接问题. 我的测试显示,当脚本在数据库服务器上运行时,根本无法重现该错误,但是当从Web服务器的命令行运行时确实发生了错误.这证明支持我的预感,即问题与连接有关,并且与网站或数据库服务器无关. 这将注意力集中在防火墙的设置上,将网站的DMZ与SQL服务器所在的内部网络分开.这个防火墙是一个负载平衡的对 – 我们最终能够找到一个微妙的配置差异,这导致第二个盒子终止通过第一个盒子启动的连接. 这个特定问题似乎不太可能导致问题 – 但您可能会发现提出测试的整体方法可以帮助解决问题的原因有用吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- ASP.NET中的应用程序生存期
- asp.net-mvc – ASP.NET MVC Scheduler开源?
- asp.net-mvc-3 – 可以用“@:@”修复的MVC4剃刀的可能的突
- asp.net-mvc – MVC6剃须刀如何检测调试模式?
- asp.net – 当Visual Studio 2013打开Web项目时,IISExpress
- asp.net-mvc-3 – ASP.NET MVC重定向到没有物理重定向的操作
- 使用FormsAuthentication.SetAuthCookie(用户名,false)后,f
- asp.net-mvc – 如何从mvc中的控制器中设置隐藏字段的值
- ASP.NET中的SMTP头注入?
- asp.net-mvc – 在@ Html.ActionLink中放置@ Html.DisplayF
- Response.Redirect在ASP.NET中将数据POST到另一个
- asp.net – 获取ListView中动态添加的控件的值
- asp.net-mvc – ASP.net MVC 4中的条件@ Scripts
- asp.net-mvc – 通过子域名到mvc或api的ASP.NET路
- asp.net-mvc – 在ASP.NET MVC中使用DotNetOpenI
- entity-framework – 无法从程序集’EntityFrame
- asp.net-mvc – RedirectToAction重定向查询参数
- ASP.NET和Web Tools 2012.2引用LESS文件
- asp.net – 什么条件导致Web浏览器显示“Page Ex
- asp.net-ajax – 如何在ASP.NET AJAX中实现文件下