Is there a way to check connections in pool from C# code?
I am developing an obfuscation tool that basically hammers a DB, on a dedicated SQL server (used only for this tool), to retrieve records, perform some data manipulation and then update those records. This is all being done with LINQ to SQL. I am using tasks and parallel loops to run as many updates as possible, concurrently. All SQL is done from the same connection string. Originally I used the default max connection pool size (100) assuming it would be enough. It seems after running for a few hours (as this tool is updating millions of records), it starts to puke as it cannot establish a connection. 开发者_如何学编程 After looking into the connection pool, I noticed that I had reached my limit of 100. Therefore I increased the limit to 200. This is working much better however one of my processes (failed to mention this runs in a couple of processes) ends up failing after about 3 hours. The connection pool did not seem overused and I am therefore left scratching my head. I have checked numerous areas in my code to ensure all connections are being disposed, which they are. I even moved all connection code to one central location so now the code only establishes connections from one location. To rule out the idea of the connection pool being maxed out, I would like to use C# to query the pool to see the limit upon an exception when trying to connect. Is this possible? Does the framework have code to do this or will I be required to run a SQL stmt to determine this?
FYI: I am using 4.0 and SQL 2008.
Thanks in advance!
It looks like I was able to use PerfMon to monitor the connection pool. This showed me that I was actually hitting the pool limit, and to my surprise, the pool was not 200 like I thought I had set it. Problem solved! Sometimes, we create such complex code we cause our own problems!
Side note - I was originally using sp_who2 but when my exception(s) occurred, the pool was cleaned-up so I couldn't get an accurate reading.
精彩评论