How do I find a closed connection? The timeout has expired. Waiting period before completing the operation or the server is not responding

I've had this problem before and found that basically I have a connection that I'm not closing fast enough (leaving connections open and pending garbage collection isn't really the best practice).

Now I get it again, but I can't find where I am leaving my connections open. By the time the error occurred, the old connections had been removed in the database, so I can't see the last command of the last connections (very helpful last time I had this problem).

Any idea how I can measure my code or database to keep track of what's going on so I can find my offending piece of code?

+3


source to share


2 answers


The error you provide does not really indicate a connection that remains open; there is most likely a request that is taking longer than the application is expecting. you can increase the response time and you can use Sql to find which queries are most taxable.



+1


source


Hopefully you have one data access layer class, not a whole bunch of classes, each of which creates its own connection, right? What language do you use? If you are using C #, the biggest cause of this problem is DataReaders and returning those objects to the top levels. Most likely some client class doesn't close the DataReader it got from your DAL class, leaving the connection open / blocked for someone who knows how long. Monitor the returned DataReaders and make sure your client classes close / remove them correctly.



I also started thinking about redesigning your data access layer by implementing a one-off pattern and possibly returning POCOs instead of Data objects (... Tables, ... Sets, ... Readers).

0


source







All Articles