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



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...@xxxxxxxxxxx> wrote:
<ramne...@xxxxxxxxx> wrote in message

news:1171294709.676296.131440@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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 -


.



Relevant Pages

  • Close and Dispose argument
    ... here is an email conversation between me and Microsoft ... connections from the pool is still a debate. ... Programming with Microsoft ADO.NET" module 2, p 18: "Calling the Dispose ... method removes the conneciton from the connection pool". ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: the difference between SqlConnection.IDisposable.Disp­ose() and SqlConnection.Dispose()
    ... Framework code to see what it does. ... As long as you use Close on the Connection you're ... Sure, you can call Dispose if you want to, but it won't help the ... > isn't a property or something of SqlConnection. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: What is the difference between Dispose and Close
    ... Dispose and Close both return the connection to the pool. ... were calling neither or the logic let the PSP sneak away without calling one ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Question about Dispose
    ... There is a common misconception going around regarding SqlConnection close ... Dispose does only two things, first it clears the SqlConnection connection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Question about Dispose
    ... There is a common misconception going around regarding SqlConnection close ... Dispose does only two things, first it clears the SqlConnection connection ...
    (microsoft.public.dotnet.framework.adonet)

Loading