Diagnosing SqlConnection leaks?

有些话、适合烂在心里 提交于 2019-12-06 09:46:31

问题


I'm running into an issue with a web application that is exhausting all available connections in the connection pool. I seem to recall some good tools used to diagnose all active connections, but am drawing a blank. What are some good options for diagnosing this issue?


回答1:


.Net memory profiler of WinDbg with SOS will allow you to track down who is holding references to your connection objects, with that information you should be able to track down the offending methods.




回答2:


Are you using SqlDataReader objects in your application? A SqlDataReader object will keep its connection open until it is closed.




回答3:


I vote for a code review. I once had a similar situation with an app built by third parties, and doing a search for connection quickly exposed it didn't do using/finally to make sure connections were closed when an exception occured.

Also as pointed out by Michael, you have to make sure connections used by data readers are closed. You can specify the connection is closed when the reader is closed, then for those cases just make sure the data reader is disposed (with an using(){} )




回答4:


You can run sp_who to see active connections from the SQL server, but, it's likely you aren't closing out your connections as other have suggested. However, if you are closing the connections, but reopening them immediately (like in a loop reading a text file or something), you can use them all even though you think you are closing them (look at Connection Pooling). If you post an example of your code, I think you'll get a better answer.



来源:https://stackoverflow.com/questions/687391/diagnosing-sqlconnection-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!