We are getting following error in our
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 you want to find out what is eating up your connections, try this:
- Implement correctly all connections inside
usingblocks to close/dispose connections (as you said, this is already done)
- Check which user/machines are keeping opened connections. Run this query to identify the database id:
select distinct dbid, DB_NAME(dbid) FROM sys.sysprocesses where dbid > 0
Then, use this query to inspect all opened connections, replacing the dbid:
SELECT dbid, DB_NAME(dbid) as DatabaseName, COUNT(dbid) as ConnectionCount, loginame as LoginName FROM sys.sysprocesses WHERE dbid = 1 GROUP BY dbid, loginame ORDER BY count(dbid) desc
This can give you some hint about who is keeping too much connections opened.
- Implement pooling in connection string to limit connections. Use this in your application connection string:
Pooling=true; Min Pool Size=1; Max Pool Size=5