我们遇到与this StackOverflow Q ...
相同的错误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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
...除了在引用的StackOverflow Q中,一旦发生错误,他们需要重新启动SQL Server - 而我们不会。我们每天会收到一次这个错误,或者每隔几天就会收到一次错误 - 错误发生后一切都很好,直到下一次错误发生。
这让我们认为这不是“忘记关闭联系”的问题。我们有一个中等繁忙的ASP.NET 4.0 WebForms / SQL Server 2008 R2应用程序;但我们非常肯定我们没有超过数据库连接的最大数量。
对此问题的任何想法,或诊断方法?
答案 0 :(得分:2)
我想我会评论我们在此方面的进展。
虽然没有一个SQL Server文档/文章/博客提到这个错误可能是由服务器忙碌造成的,但我找到了一个forum posting,其中一些经验丰富的IT专业人员名为Matt Neerincx表示可以,如下:
Possible reasons for this error include:
1. Poor network link from client to server.
2. Server is very busy (meaning high CPU) and cannot respond to new connection attempts.
3. Server is running out of memory (so high memory usage for SQL).
4. tcp-ip layer on client is over-saturated with connection attempts so tcp-ip layer rejects the connection.
5. tcp-ip layer on server side is over-staturated with connection attempts and so tcp-ip layer is rejecting new connections.
6. With SQL 2005 SP2 and later there could be a custom login trigger that rejects your connection.
You can increase the connect timeout to potentially alleviate issues #2, #3, #4, #5. Setting a longer connect timeout means the driver will try longer to connect and may eventually succeed.
To determine the root cause of these intermittent failures is not super easy to do unfortunately. What I normally do is start by examining the server environment, is the server constantly running in high CPU for example, this points to #2. Is the server using a hugh amount of memory, this points to #3. You can run SQL Profiler to monitor logins and look for patterns of logins, perhaps every morning at 9AM there is a flurry of connections etc...
因此,我们目前正沿着这条路走下去 - 减少了在一些批量查询中同时执行的查询数,优化了一些查询等等。
此外,在我们的app连接字符串中,我们增加了连接超时,并将Min Pool Size设置为20(认为尝试确保应用程序可以抓取一些现有的,未使用的连接,而不是需要建立新的连接)。
此时此刻已经差不多48小时没有收到错误;让我们充满希望。