服务器 1:SQL Server 2008 标准版
服务器 2:Windows 2008 Server R2、IIS 7.0
服务器 2 上的网站需要服务器 1 上的 SQL Server 中的数据。
一切正常一段时间(有时是几周)。然后,在负载很重的情况下,Server 2 报告它无法连接Server 1 上的SQL Server。一旦Server 2 上的IIS 报告它无法连接到Server 1 上的SQL,直到重新启动Server 2 上的IIS 后,情况才会好转。也许重新启动应用程序池和完全重置 IIS 一样有效。我不确定。
我尝试更改连接字符串以将连接池大小增加到不合理的大值 (1,000)。失败仍然发生。
该网站是用 C# 编写的。数据访问层是NHibernate。
这是异常的开始:
[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.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +428
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
NHibernate.Connection.DriverConnectionProvider.GetConnection() +60
NHibernate.Impl.SessionFactoryImpl.OpenConnection() +39
任何想法为什么会发生这种情况?如何诊断/修复它?我很沮丧,正在考虑删除 NHibernate,这需要几个月的时间,并且可能会导致许多其他类型的问题。
最佳答案
我认为您还必须增加连接超时值和连接池。这样它就不会在重负载下释放与 SQL Server 的连接。