问题描述
我看到错误可怕的之前从池中获取一个连接过去的超时时间。
I'm seeing the dreaded "The timeout period elapsed prior to obtaining a connection from the pool" error.
我已经搜查了code任何未关闭数据库连接,但找不到任何。
I've searched the code for any unclosed db connections, but couldn't find any.
我想这样做是:下一次我们得到这个错误,对系统转储的的特效或HTTP请求持有所有句柄的列表,所以我可以找出哪些code引起的问题。
What I want to do is this: the next time we get this error, have the system dump a list of which procs or http requests are holding all the handles, so I can figure out which code is causing the problem.
更妙的是,看多长时间的手柄已经举行,所以我可以当场使用的,但是,未关闭连接。
Even better would be to see how long those handles had been held, so I could spot used-but-unclosed connections.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
有用于监控连接池的一些很好的联系。做一个谷歌搜索.NET连接池的监控。
There are some good links for monitoring connection pools. Do a google search for ".net connection pool monitoring".
我提到了,而其中一篇文章背 (请注意,这是旧的,但仍然包含有用的信息)。它有监控连接池的一些信息,但一些伟大的见解,到泄漏可能存在的为好。
One article I referred to a while back was Bill Vaughn's article (Note this is old but still contains useful info). It has some info on monitoring connection pools, but some great insights as to where leaks could be occuring as well.
有关的监测,他建议;
For monitoring, he suggests;
监视连接池
好了,你打开的连接和关闭它,并想知道,如果
连接还是很到位的,含情脉脉的在一个连接池
空气床垫。嗯,有几种方法来确定多少
连接仍然存在(仍然连接),甚至他们
是做。我讨论其中一些在这里和我的书:
Okay, so you opened a connection and closed it and want to know if the connection is still in place—languishing in the connection pool on an air mattress. Well, there are several ways to determine how many connections are still in place (still connected) and even what they are doing. I discuss several of these here and in my book:
·使用SQL Profiler与SQLProfiler TSQL_Replay
模板的痕迹。对于那些你熟悉的探查,
这比使用轮询SP_WHO容易。
· Use the SQL Profiler with the SQLProfiler TSQL_Replay template for the trace. For those of you familiar with the Profiler, this is easier than polling using SP_WHO.
·润SP_WHO或SP_WHO2,它从返回信息
SYSPROCESSES上显示当前状态的所有工作流程表
的各处理。一般情况下,有每一SPID服务器进程
连接。如果你命名你的连接,使用应用程序的名称
在连接字符串中的说法,这将是很容易找到。
· Run SP_WHO or SP_WHO2, which return information from the sysprocesses table on all working processes showing the current status of each process. Generally, there’s one SPID server process per connection. If you named your connection, using the Application Name argument in the connection string, it’ll be easy to find.
·使用性能监视器(PerfMon)来监视池
和连接。我在明年详细讨论这个问题。
· Use the Performance Monitor (PerfMon) to monitor the pools and connections. I discuss this in detail next.
·监视性能计数器在code。此选项允许
您可以显示或简单地监视你的连接池的健康
和建立的连接的数量。我在此讨论
后面一节本文。
· Monitor performance counters in code. This option permits you to display or simply monitor the health of your connection pool and the number of established connections. I discuss this in a subsequent section in this paper."
编辑:
与往常一样,检查出一些的other类似的帖子这里上SO
As always, check out some of the other similar posts here on SO
第二个编辑:
一旦你确认连接不是由池回收,你可以尝试另一件事是利用StateChange事件正在打开和关闭连接时确认。如果您发现有很多更为状态变化来比去封闭打开,那么这将表明,有泄漏的地方。你也可以再登录该数据在statechanged事件与时间戳一起,如果你对你的应用程序的任何其他日志记录,你可以在这里似乎是封闭到开放状态的变化开始解析为实例的日志文件,以没有相应的开闭。请参见关于如何处理StateChangedEvent更多信息。
Once you've confirmed that connections aren't being reclaimed by the pool, another thing you could try is to utilise the StateChange event to confirm when connections are being opened and closed. If you are finding that there are a lot more state changes to opened than to closed, then that would indicate that there are leaks somewhere. You could also then log the data in the statechanged event along with a timestamp, and if you have any other logging on your application, you could start to parse the log files for instances where there appears to be state changes of closed to open, with no corresponding open to closed. See this link for more info on how to handle the StateChangedEvent.
这篇关于如何找到泄漏数据库连接池处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!