Max pool size reached exception when trying to open a new connection

R

ramneekm

hi all,

i am working on a asp.net web app and using ado.net 's SqlClient Data
Provider to connect to
sqlserver 2005. I am getting the exception "Timeout expired. The
timeout period elapsed
prior to obtaining a connection from the pool. This may have occurred
because all pooled
connections were in use and max pool size was reached." . Internally i
am using a
sqldatareader to fetch data from database. The dispose of both the
reader and connection has
been called wherever they are being used. The pool size is set to
default i.e. 100. I have
tried to analyze the issue by using the sp_who2 stored procedure in
database and checking
the count of connections to the database.What is happpening is that
sometimes the pool size
limit is being maintained and increases 100. But on the other hand, it
sometimes shoot much
above the limit of 100 and then it throws the above mentioned
exception. Why does the
connection pooler sometimes enforces the pool size limit and sometimes
fails to do that
intrigues me.

But if i use GC.Collect in my code, then in that case the connection
pool limit is adhered
to and i dont get the above mentioned exception. Can someone please
help me with it and
explain why is it happening in the first place and is there a way
around it. I don't want to
use GC.Collect() in my code.

Thanks in advance
Ramneek
 
B

bruce barker

you are leaking connections. you are not always closing the connections.
you will to search your code for the bugs. having the GC will do it for
you is a bad practice. here are some rules to prevent leaking connections.

1) always use a try and finally to open/close a connection (or using).
2) never return a datareader, the opener should always close it.
3) never declaratively use a reader (from the aspx)

using a proper entity design would help prevent this.

-- bruce (sqlwork.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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top