简体   繁体   中英

Getting Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. .exception

getting Exception

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.

code:

 HotelDealsDataClassesDataContext hotelDealsDataContext = DatabaseHelper.GetHotelDealsDataContext();
 hotelDealsDataContext.spInsertAsyncHotelDealFeedRequestData(Utility.GetBinaryData(hotelDeal), DateTime.Now);

stack trace:

 at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
 at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
 at System.Data.SqlClient.SqlConnection.Open()  
 at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) 
 at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()  
 at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()  
 at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)    
 at System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters)  
 at Tavisca.TravelNxt.Deals.DataFeeders.DataAccessLayer.HotelDealsDataClassesDataContext.spInsertAsyncHotelDealFeedRequestData(Binary hotelDealData, Nullable`1 addDate)  

This exception tells you that you have exhausted the connection pool , means all connection pool is full and all connection are in use, and command string timeout is reached before getting a connection (default timeout is 15 seconds). As RePierre suggested check if you are disposing your connection properly .

Try to open connection as late as possible and close/dispose as soon possible.

General recommendation : - Always prefer USING statement for opening all connections it ensures the correct use of IDisposable objects.

TimeOutExpired

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM