SQL 服务器超时 –只是偶尔发生
我有一个网络应用程序偶尔会抛出这个错误......
异常消息:超时已到。 超时时间之前已过 操作完成或 服务器没有响应。
当我这样做时,即使通过 Management Studio,我也无法连接到 SQL Server,它说服务器超时并且无法连接。
我一重置iis,它立即就回来了。所以这显然意味着我的代码中的某些内容导致了这种情况。我有一个 MVC 站点,它使用 Linq to SQL 和 SQL 缓存依赖项并启用了服务代理。
我在整个代码中彻底使用了 using 语句,所以我确信它不是泄漏连接。阅读服务器日志会让事情变得更加混乱,因为有太多信息和警告事件,我不是系统管理员,所以很难知道发生了什么。
首先我收到一条 ASP.net 4.xxxxx 事件 ID 1309 异常消息:超时已过期。操作完成之前超时时间已过,或者服务器未响应。错误
我想我上次在以前的服务器上通过在弹出此错误时重新声明 IIS 来解决这个问题,这是我不想在这台新服务器上诉诸的方法。
所以我的问题是,我可以采取哪些步骤来尝试减少但理想情况下消除此超时错误?
非常感谢
Truegilly的任何帮助
I have a web application that occasionally will throw this error….
Exception message: Timeout expired.
The timeout period elapsed prior to
completion of the operation or the
server is not responding.
When I does I am unable to connect to SQL server, even through management studio, it’s says the server timed out and cannot connect.
As soon as I reset iis, it comes back instantly. So this obviously means it’s something in my code that’s causing this. I have an MVC site that uses Linq to SQL and SQL cache dependency with service broker enabled.
I have used the using statement thoroughly throughout the code, so im sure it’s not leaky connections. Reading through the server logs makes things more confusing as there are so many information and warning events, im not a sys admin so it’s hard to know what’s going on.
It begins with me getting an ASP.net 4.xxxxx Event ID 1309 Exception message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. error
I think I got round it last time on my previous server by restating IIS when ever this error popped up, this is something I don’t want to resort to on this new server.
So my question is, what steps can I take to try and reduce but ideally eliminate this timeout error ?
Any help is most appreciated
Truegilly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此类问题通常可以归结为两件事之一。要么您没有正确处理连接,要么您有大量繁重的查询完全接管了您的数据库服务器。
如果您没有正确处理连接,那么 IIS 会很高兴地保留它们,直到垃圾收集运行和/或它们超时。如果您的网站流量很小,那么您就不会看到这个问题。
然而,一旦流量达到挂起的连接数超过您尝试与数据库服务器建立连接的次数......那么,您将开始看到几个可能的错误之一。超时过期就是其中之一。确切的错误将取决于哪个部分发生故障:连接池、sql 服务器本身等。
您评论的修复是一个临时解决方案。随着您的流量持续增加(这是个好问题),那么代码的其他区域将导致问题再次出现。
This type of problem usually boils down to one of two things. Either you are not disposing of your connections properly or you have a number of heavy queries that are completely taking over your database server.
If you don't dispose of the connections properly then IIS will happily keep them around until garbage collection runs and/or they timeout. If you have a very lightly trafficked site then you won't see the problem.
However, once traffic reaches the point where the number of connections hanging around exceeds the number of times you are trying to make a connection to the database server.. well, you are going to start seeing one of a couple possible errors. Timeout expired is one. The exact error is going to depend on which part is falling over: the connection pool, the sql server itself, etc.
The fix you commented on is a temporary solution. As your traffic continues to increase (good problem to have) then other areas of your code are going to cause the issue to come up again.