AJAX connection leak

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?
 
M

Mike

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top