AJAX connection leak

  • Thread starter Thread starter David Cohen
  • Start date Start date
D

David Cohen

I have an AJAX page where I am doing a partial page refresh every 5 seconds.
My Page_Load() function contains the following:

SqlConnection conn = new SqlConnection(...);
conn.Open();
// database access stuff
conn.Close();

Even though I am closing the connection, I find that whenever this page
stays open for a long time, I get an "all pooled connections were in use and
max pool size was reached" error message. Does anybody know why?
 
Hi David,

What exactly do you do between Open and Close? If you open a datareader,
you'll need to close it, too.

I have a couple of suggestions:
1. Cache a single connection in the Application variable
2. If you use your code, make sure that the conn.Close in the finally part
of a try catch.
3. As mentioned, close datareader in finally, also or use using(
SqlDataReader reader = cmd.ExecuteReader())..

Mike
http://www.homemadepride.com
 
Back
Top