【问题标题】:Getting exception Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool获取异常超时已过期。在从池中获取连接之前经过的超时时间
【发布时间】:2014-01-14 06:40:41
【问题描述】:

收到异常建议我,我不想增加连接超时

超时。在从池中获取连接之前超时时间已过。这可能是因为所有池连接都在使用中并且达到了最大池大小。

堆栈跟踪:

堆栈跟踪位于 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection 拥有连接)在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection 外部连接,DbConnectionFactory 连接工厂)在 System.Data.SqlClient.SqlConnection.Open() 在 System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser 用户)在 System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() 在 System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() 在 System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式 查询)在 System.Data.Linq.DataContext.ExecuteMethodCall(对象 实例,MethodInfo methodInfo,Object[] 参数)在 Tavisca.TravelNxt.Deals.DataFeeders.DataAccessLayer.HotelDealsDataClassesDataContext.spInsertAsyncHotelDealFeedRequestData(二进制 hotelDealData, Nullable`1 addDate)

在 Tavisca.TravelNxt.Deals.DataFeeders.Entities.AsyncHotelDealFeedRequest.Add(HotelDeal 酒店交易)在 Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.b__0(HotelDeal 交易)在 System.Collections.Generic.List1.ForEach(Action1 操作)在 Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.UploadDeals(List`1 hotelDeals,字符串 sessionId)在 Tavisca.TravelNxt.Hotel.Plugins.DealsHandler.OnAfterProcessImplementation(CallHandlerContext 上下文,对象[]&输入参数,对象&响应)

【问题讨论】:

    标签: c# .net linq


    【解决方案1】:

    在您完成数据库连接后,您很可能没有正确关闭它们。一种可能性是您忘记在几个位置关闭一个或多个连接。另一个是执行 sql 命令时出现异常,导致无法到达 close 语句。

    按照以下模式确保您正确关闭所有连接:

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 2014-01-29
      • 2014-07-07
      • 1970-01-01
      • 2010-12-11
      相关资源
      最近更新 更多