简体   繁体   中英

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

Getting exception suggest me on this , i don't want to increase connection timeout

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.

stacktrace:

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)

at Tavisca.TravelNxt.Deals.DataFeeders.Entities.AsyncHotelDealFeedRequest.Add(HotelDeal hotelDeal) at Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.b__0(HotelDeal deal) at System.Collections.Generic.List 1.ForEach(Action 1 action) at Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.UploadDeals(List`1 hotelDeals, String sessionId) at Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.OnAfterProcessImplementation(CallHandlerContext context, Object[]& inputParameters, Object& response)

You're most likely not closing your DB connections properly after you're done with them. One possibility is that you forgot to close one or more connection in few locations. Another is that you have exceptions when executing sql commands which prevent you from reaching the close statement.

Follow the following pattern to make sure that you're closing all connections properly:

SqlConnection connection = null;
try
{
    connection = new SqlConnection(...);
    //all other stuff goes here
}
catch{}
finally
{
   if(connection != null)
      connection.Close(); //This will always close the connection, even with exceptions.
}

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