Click here to Skip to main content
14,545,020 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 3

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.
   
Comments
rushdi obeidat 18-Jul-12 6:42am
   
thx a lot i will try it.
pradiprenushe 18-Jul-12 6:43am
   
welcome.
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.

Dim reader As DbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return reader
   
Rate this:
Please Sign up or sign in to vote.

Solution 8

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))
{
};
   
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;
}
}
Rate this:
Please Sign up or sign in to vote.

Solution 5

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
   
Comments
Rohit_shrma 14-Aug-14 9:53am
   
SqlConnection doesnt have method ClearAllpools()

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100