最近我开始在我的web应用程序的日志文件中看到间歇性错误。 从应用程序的不同位置提出错误始终是与位于另一个服务器上的数据库连接失败:
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) ---- System.ComponentModel.Win32Exception (0x80004005): Access is denied
要么
The underlying provider failed on Open. ---- System.Data.SqlClient.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): Access is denied .... at System.Data.Entity.Core.EntityClient.EntityConnection.Open() ClientConnectionId:00000000-0000-0000-0000-000000000000
我在Win Server 2008 R2上使用Microsoft SQL Server标准版(64位)10.50.4000.0
我检查了:
1数据库Autoclose设置为OFF
2我检查了APP和DB服务器的事件日志,没有发现任何与sqlserver或networking错误有关的东西。 事件日志但是包含Schannel错误,但是从我Googlesearch它是不相关的。
如果在您的网站出现错误的时刻,您可以尝试以另一种方式连接到数据库(也许是SSMS)。 如果你不能,你可以连接到数据库驻留的服务器? 如果您可以在网站无法连接的同时连接,您是否使用同一个用户? 由于数据库问题(停止本身或者太忙而无法响应),连接到数据库服务器的networking错误,或者因为对工作数据库的用户validation错误,确定网站是否无法连接到数据库非常重要。 采取什么行动取决于你有哪些问题。
至于如何做到这一点,你可能会添加一些网页代码来捕捉错误,并发送一封电子邮件给你。 那么你可以在那个时候检查数据库。 如果这是不可能的,也许你可以编写一个小的命令行应用程序来连接到数据库,并将一个date时间标记写入一个文件以及发生的任何错误。 然后设置一个计划任务,每5分钟左右运行一次程序。 您甚至可以将该命令行应用程序放在Web服务器和另一台服务器上以获取更多信息(您也可以尝试以不同的用户身份运行该应用程序)。
例如,如果数据库正常,networking连接正常,并且用户有时无法连接,那么由于来自某人/某人的太多无效login尝试的locking策略,用户可能偶尔会被locking在networking上。 或者,由于计划备份正在利用数据库服务器上的所有可用资源,因此也许数据库在一天中的某些时间根本没有响应。 等等。