1

I'm having Trouble with the following Error:

"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."

It seems that the error is in the following code block:

da = new SqlDataAdapter(command);
command.CommandTimeout = 100;
da.Fill(dt);
conn.Close();
return dt;
Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32
  • Probably should wrap the command and the connection in a using statement. That could help with your connections leaking. – Kevin Up Jul 05 '17 at 11:57

2 Answers2

0

It's hard to say with such a small amount of code in your question but this error can occur when you're not disposing of your db connection objects properly. The "using" statement may help you out of this problem. There is a SO issue with the same error message and code examples here: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. which may help.

Community
  • 1
  • 1
jonnarosey
  • 520
  • 1
  • 8
  • 19
0

When you open any connection and not close after completion then it will show you above error. because there is app pool size limit, after limit exceeds it will show you error.

So try to close connection after completion of method. Or for the time being you can set max pool size in web.config file as 1000 or more.

yatin parab
  • 174
  • 6
  • What i don't get is that i already have an conn.Close() in the code. So why is there the possibility of a not closed connection? –  Jul 07 '16 at 13:18
  • If your site having multiple session on and you are not closing connection each time after open then it will be the issue of app pool, you are telling me about current connection but we want to see all the database connection which are in open state, just fire command sp_who2 you will get info about all connection. – yatin parab Jul 07 '16 at 14:41