Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
1.80/5 (4 votes)
Does any one know what is going on with this error and how can i solve it ?

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. at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open()

Thanks in advance
Posted
Updated 15-Jan-19 1:32am

Yes. The timeout expired. The timeout expired 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.

What this (plain English) message means is that your code waited for a database connection but the timeout ( which you set ) expired before it could get a connection, probably because the number of connection in the pool ( which you set ) was too low for the number of connections you were attempting, or there was a network time out, i.e. the connection between your IIS and your SQL Server was too slow to serve a connection.
 
Share this answer
 
Comments
rushdi obeidat 18-Jul-12 5:10am    
ok .. but the number of maximum connection in the application pool is set to be 5000
Christian Graus 18-Jul-12 5:34am    
Then that means that your connection to your SQL Server is too slow and timed out. Like I said. You should consider when you ask a question, explaining why you don't think the problem is what the error says. In this case, it's making a guess, and can be wrong.
Execute this query on SqlServerStudio

SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame


You will get the idea how many connections are open for your database.
I think you are not properly closing connections. Or may be connection is opened somewhere in loop.
 
Share this answer
 
Comments
rushdi obeidat 18-Jul-12 6:42am    
thx a lot i will try it.
pradiprenushe 18-Jul-12 6:43am    
welcome.
I got this issue recently as one function is creating DbDataReader and returns to other function for iterating. After closing the dataReader in the consumer function it was not closing the connections. So used the below method to create DbDataReader which force to close the connection when the reader closes.

C#
Dim reader As DbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return reader
 
Share this answer
 
getting This Issue because of the exceeding max pool size.
Note: The default pool size is max 100 and 15 seconds for the connection timeout

To Resolve this issue check the following things...
1 You are closing the connection after using it.
Example:
SqlConnection con= new SqlConnection(connString);
SqlCommand cmd= new SqlCommand("SELECT * FROM ReatilersDetails", con);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Close();
con.Close();

2) Explicitly close the connection when done.
con.Close();

3) Use the connection in a Using block.
using(SqlConnection con= new SqlConnection(connString))
{
};
 
Share this answer
 
Comments
aalhussein 1-Apr-20 15:42pm    
Hi Rohi,
If I use the word " using ", is it going to close the connection automatically after getting the data from the DB.
I wil lpost my code for your review and do appreciate your comments to improve and to avoid exceeding connection:
public int InsertUpdateDelete(string mySql, Dictionary<string, object=""> myPara)
{
int rtn = 0;
using (SqlCommand cmd = new SqlCommand(mySql, con))
{
cmd.CommandType = CommandType.Text;
foreach (KeyValuePair<string, object=""> p in myPara)
{
cmd.Parameters.AddWithValue(p.Key, p.Value);
}
using (con)
{
con.Open();
rtn = cmd.ExecuteNonQuery();
con.Close();
}
}
return rtn;
}

public DataSet getDataSetPassSqlDic(string mySql, Dictionary<string, object=""> myPara)
{
DataSet ds;
using (SqlConnection cn = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand(mySql, cn))
{
foreach (KeyValuePair<string, object=""> p in myPara)
{
cmd.Parameters.AddWithValue(p.Key, p.Value);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds = new DataSet();
using (cn)
{
cn.Open();
da.Fill(ds);
return ds;
}
}
}
}

public SqlDataReader getDrPassSql(string mySql, Dictionary<string, object=""> myPara)
{
using (SqlCommand cmd = new SqlCommand(mySql, con))
{
foreach (KeyValuePair<string, object=""> p in myPara)
{
// can put validation here to see if the value is empty or not
cmd.Parameters.AddWithValue(p.Key, p.Value);
}
con.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
}
use SqlConnection.ClearAllpools(); method in Page_Unload event this will close all the connections

it worked out for me .

or otherwise close all connections explicitly
 
Share this answer
 
Comments
Rohit_shrma 14-Aug-14 9:53am    
SqlConnection doesnt have method ClearAllpools()
Member 11893178 13-Jun-21 15:50pm    
use SqlConnection.ClearAllPools();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900