Can't anyone help me with this? - "..timeout period elapsed prior to obtaining a connection from the pool..."

I posted this problem but no one responded. I figured I'd try one last time.

I'm having a wierd problem. I've been using Visual Studio.NET 2003, and writing an app that up to now has been working perfectly. All of a sudden an error comes up and have no idea what it means or how to stop it from happening. The error is: "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occured because all pooled connections were in use and max pool size was reached." 

OK, first of all the max pool size in SQL Server 2000 is set to unlimited. Next, in the code, I check the connection state just before I fill the data adapter (Step Through - F8) - and it's closed. So no unnecessary connections are open. 

All that's not really the wierd part. The wierd thing is when I run the exe file from the bin directory in Windows Explorer (after building/compiling it) it all works PERFECTLY! But running it within the VS.NET environment - it gives me that error. Is this a service pack thing, me or does VS.NET run the same exact exe file differently than if running it by just double clicking on it in Windows Explorer  

Driving me nuts. Thanks ahead of time, 
Denvas


Answer this question

Can't anyone help me with this? - "..timeout period elapsed prior to obtaining a connection from the pool..."

  • Jeff Walsh

    Yeah, I also had the same problem. But by setting pooling = false, the problem has vanished. 
    This was because I was opening and closing the connection inside a loop, and the available connections were over the limit i.e. 30. 

    One more approach could be that done open and close the connection inside the loop. Open it before the loop and close it after the loop. Anyways, thanx for help. 

  • aalford

    Thanks for the post.  Without ';Pooling=False' - it still has the same problem - even with ";Connection Lifetime=30". In addition - nobody has been able to explain why this error exists after running/compiling the exe from VB.NET as opposed to running it from the bin.

    Thanks though,
    Denvas

  • Najm

    Thanks Chris. 

    That did it. 

    Edward

  • Johan Delimon

    Thanks Chris.

    That did it. I simply added Pooling=False to the connection string and it works. Its working pretty crappy mind you, but nonetheless functional. Still not understanding how a connection string is affected by how the project is compiled. But at this point I don't care anymore - as long as I can get back to work.

    Thanks again,
    Denvas

  • RS_Trans

    Can't help-- but have the same type of problem from time to time.  I have a 100 gig SQL database with 300 users.  It will run for months with out a problem then for about an hour or two I get the same message.  Then ok for weeks.  I have driven the DBA and network people nuts. 
  • ebc

    Our investigation revealed that the .NET SQLConnection Connection Pool is - at Connection Timeout (Default 4 hours) - doing something that seems to be statistical analysis - and during this analysis - no more connections can be retrieved from the pool. In our case we are using a connection from the pool 5 times a second. When the pool statistical analysis runs - it is analysing 5 * 60 * 60 * 4 (Hours) worth of statistical data. This process takes about 20 minutes. 20 minutes where  the pool is unavailable !!! Solution - make the timeout about 30 seconds so that the analysis has a lot less data to analyse - and then the lag created by this analysis is one hellova lot shorter and has virtually no impact.

    i.e. Add ";Connection Lifetime=30" to your connection string. Timeout is now 30 seconds.

  • maxi_byte

    I am getting the same error.  My application is not multi-threaded. 

    Erro:  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.

    If anyone has an answer - please help!

    Thanks,
    Anxiously Waiting

  • djalexd

    If its any consolation I recently JUST started having the same issue on one of my projects.  From what I've read it generally relates to the connection string to SQL.
    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconconnectionpoolingforsqlservernetdataprovider.asp

    This is the info I could find on changing the pool settings but I'm at a loss to determine why it has just started when as far as I can tell nothing has changed in how this is configured.

    regards,

    Chris

  • tnyx

    I had the exact same error. 
    And i ve increased the pool size and decreased the connection timeout period. And the problem gone. I m not sure that is correct solution but, now i can breath :)

  • snktheone

    Sounds like a try.  Now exactly where do I change these settings  Are you talking about VS.NET or SQL Server 2K  Thanks for the help.

    Isn't it wierd that SO many people have seen this post; I'm sure by just those numbers, even a small percentage have had the same experience AND found a complete fix for this. 

    Can't believe no one can give me an explanation why running an app from within VS.NET would be different from running the same EXACT compiled exe from the bin directory (Windows Explorer).  Usually a lot of experts on this forum.

    - Denvas

  • Shane Gidley

    I am also getting the same problem. I start a new thread to execute an sql command. This happens many times per second. I tried setting pooling to false but then I got an out of memory exception. Should I get the number of threads in a pool and check to see if it's less than the max  I have my threads running in the background, I don't know if that matters. I am running my thread like this:

    System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(executeSQL));
    myThread.IsBackground=true;
    myThread.Start();

    public void executeSQL()
    {
    string myConStr = sqlConnection1.ConnectionString;
    SqlConnection myConn = new SqlConnection(myConStr);
    SqlCommand myCmd = new SqlCommand(sb.ToString(), myConn);
    myConn.Open();
    try
    {
    myCmd.ExecuteNonQuery();
    }
    catch(Exception ex)
    {
    System.Threading.Thread.CurrentThread.Suspend();
    MessageBox.Show("Error executing SQL, possibly there was a character in the input that messed up the import. Please contact Thomas. Input string: "+sb.ToString()+"\nERROR:\n\n"+ex.ToString());
    }
    finally
    {
    myConn.Close();
    }
    }

  • CarlaOR

    I took a look at the link you gave me. Very informative. Unfortunately, Microsoft describes everything as if we're all engineers. It's like I have to reference other books just to understand a word they mention in a sentence. LOL

    But, I got the basic idea - but it still makes me wonder why it works PERFECTLY when the compiled exe runs on a clients' computer or straight from the bin directory. BUT when I run it from within VB.NET 2003 (hitting F5) that's when I get problems. All I'm doing is getting data. And not from a particular call. If I simply skip one ExecuteScalar, and choose the next one - I get this problem either way (Again, only in VB.NET 2003 Ent. Arch.).

    Is the VB.NET environment conflicting with my applications' process

    I'm confused.

    Were you getting your problem when opening the exe directly or within the design environment

    thanks,
    Denvas

  • Snake_122

    Thank you so much.  I'm going to look into it. At least I have a starting point now.  

    Thanks,
    Denvas

  • Digamber

    I had the exact same error as you have described a while ago.  What I found out was that the pool size that it refered to by the error has nothing to do with the SQL database although, like you, I thought it did at first. The pool whose max is reached is .NET thread pool. This is set at 30 connections and cannot be tweaked no matter what you do. I found an article which explained all this: 

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/progthrepool.asp

    Anyway after poking around I found that I was calling a method in my timer tick event over and over and over again. I fixed this and it solved the problem.

    hope this helps, 

    sivilian

  • Can't anyone help me with this? - "..timeout period elapsed prior to obtaining a connection from the pool..."