Home All Groups Group Topic Archive Search About

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

Author
12 Feb 2007 3:38 PM
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

Author
12 Feb 2007 5:09 PM
Miha Markic [MVP C#]
Are you sure you are not leaking connections?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<ramne***@gmail.com> wrote in message
Show quote
news:1171294709.676296.131440@v45g2000cwv.googlegroups.com...
> 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
>
Author
12 Feb 2007 6:14 PM
David Browne
<ramne***@gmail.com> wrote in message
Show quote
news:1171294709.676296.131440@v45g2000cwv.googlegroups.com...
> 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.

No it's not.  Look harder.

Show quote
>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.
>


Yep.  You are leaking connections.  The fact that GC.Collect clears it up
makes it certain.  Somewhere you are letting either a SqlConnection or an
open DataReader go out of scope without closing it.

David
Author
13 Feb 2007 7:12 AM
ramneekm
Hi i am wrapping the sqlconnection in using statement.so there is no
doubt that dispose is not getting called on sqlconnection.
On Feb 12, 11:14 pm, "David Browne" <davidbaxterbrowne no potted
m***@hotmail.com> wrote:
Show quote
> <ramne***@gmail.com> wrote in message
>
> news:1171294709.676296.131440@v45g2000cwv.googlegroups.com...
>
> > 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.
>
> No it's not.  Look harder.
>
>
>
>
>
> >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.
>
> Yep.  You are leaking connections.  The fact that GC.Collect clears it up
> makes it certain.  Somewhere you are letting either a SqlConnection or an
> open DataReader go out of scope without closing it.
>
> David- Hide quoted text -
>
> - Show quoted text -
Author
13 Feb 2007 3:12 PM
David Browne
<ramne***@gmail.com> wrote in message
news:1171350745.684077.327380@m58g2000cwm.googlegroups.com...
> Hi i am wrapping the sqlconnection in using statement.so there is no
> doubt that dispose is not getting called on sqlconnection.

What about SqlDataReaders, are they all wrapped in using statements?

David
Author
13 Feb 2007 5:29 PM
ramneekm
I have closed the datareaders explicitly in finally block.

On Feb 13, 8:12 pm, "David Browne" <davidbaxterbrowne no potted
m***@hotmail.com> wrote:
Show quote
> <ramne***@gmail.com> wrote in message
>
> news:1171350745.684077.327380@m58g2000cwm.googlegroups.com...
>
> > Hi i am wrapping the sqlconnection in using statement.so there is no
> > doubt that dispose is not getting called on sqlconnection.
>
> What about SqlDataReaders, are they all wrapped in using statements?
>
> David

AddThis Social Bookmark Button