gpt4 book ai didi

linq-to-sql - SQL Server "network-related or instance-specific error"每天一次左右(困惑!)

转载 作者:行者123 更新时间:2023-12-01 04:06:37 26 4
gpt4 key购买 nike

我们遇到了与 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 应用程序;但我们很肯定我们没有超过数据库连接的最大数量。

关于这个问题的任何想法,或诊断方法?

最佳答案

我想我会评论我们在这方面的进展。

虽然没有任何 SQL Server 文档/文章/博客提到此错误可能是由 引起的。服务器繁忙 ,我找到了一个forum posting其中一些名为 Matt Neerincx 的经验丰富的 IT 专业人员表示它可以,如下所示:

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...

所以我们目前正在走这条路——减少在我们的一些批处理查询中同时执行的查询数量,优化我们的一些查询等。

此外,在我们的应用程序连接字符串中,我们增加了连接超时,并将 Min Pool Size 设置为 20(认为尝试确保应用程序获取一些现有的、未使用的连接,而不是需要建立新连接)是好的。

此时,已经将近 48 小时没有收到错误消息;让我们充满希望。

关于linq-to-sql - SQL Server "network-related or instance-specific error"每天一次左右(困惑!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8918891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com