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

Discussion in 'ASP .Net' started by ramneekm@gmail.com, Feb 12, 2007.

  1. Guest

    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
     
    , Feb 12, 2007
    #1
    1. Advertisements

  2. bruce barker Guest

    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)



    wrote:
    > 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
    >
     
    bruce barker, Feb 12, 2007
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vladimir Davidov

    "max pool size was reached" problem again!

    Vladimir Davidov, Nov 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    9,400
    +The_Taco+
    Nov 20, 2003
  2. =?Utf-8?B?Sm9u?=

    Timeout Expired...max pool size was reached.

    =?Utf-8?B?Sm9u?=, Oct 3, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    802
    =?Utf-8?B?Sm9u?=
    Oct 3, 2006
  3. Tiwkiz
    Replies:
    0
    Views:
    944
    Tiwkiz
    Jan 27, 2007
  4. Allan Ebdrup
    Replies:
    1
    Views:
    579
    Allan Ebdrup
    May 14, 2007
  5. jobs
    Replies:
    1
    Views:
    6,016
    bruce barker
    Nov 10, 2007
  6. steven

    determining max pool size

    steven, Apr 8, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    1,427
    steven
    Apr 8, 2008
  7. Wei  Lu
    Replies:
    2
    Views:
    6,559
    Wei Lu
    Feb 16, 2009
  8. David Karr
    Replies:
    2
    Views:
    339
    Willem
    Apr 7, 2011
Loading...