c# - Firebird 数据库上的错误 MaxPoolSize

标签 c# connection-pooling firebird

在连接到数据库时,我使用连接池和 Firebird 数据库。我使用 FirebirdSql.Data.FirebirdClient 版本 2.6.5.0。 我有以下连接字符串:

<add name="db" connectionString="Server=***;user   
id=***;password=***;Charset=ANSI_CHARSET;Database=***;
Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=10" 
providerName="FirebirdSql.Data.FirebirdClient" />

我有以下使用数据库连接的代码:

IEnumerable<Orders> ord = new List<Orders>();
using(FbConnection fbCon = new FbConnection("my connection string"))
{
    fbCon.Open();
    using(FbCommand command = fbCon.CreateCommand())
    {
        command.CommandText = "SELECT first 100 ID, SYMBOL, NUMBER, POS FROM Z1";
        Debug.WriteLine(string.Format("Before Close: {0}", FirebirdSql.Data.FirebirdClient.FbConnection.GetPooledConnectionCount(fbCon)));
        ord= command.ExecuteReader(CommandBehavior.CloseConnection).ConvertToList<Orders>();
    }
}

但是,我收到错误:

Timeout exceeded.
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckMaxPoolSize ()
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckOut ()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open ()

错误是由达到 MaxPoolSize 引起的...每次当我调用上面的代码时,在输出窗口中我的辅助消息:

Before Close: 1
Before Close: 2
...
Before Close: 10

最佳答案

您的代码可能会导致异常并且永远不会到达 Close(),从而使连接保持打开状态,这可能会导致打开太多连接。

您可能想尝试在代码中实现 Using()。

Here is an article that describes this in more detail.

我在达到最大连接数时遇到了类似的问题,而 Using() 确实有所帮助。

关于c# - Firebird 数据库上的错误 MaxPoolSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20905850/

相关文章:

c# - List<T>.ForEach() 方法消失了吗?

mysql - 如何解决Pool的_connectionQueue过多问题?

sql - 从查询中选择 FIRST X,但获取计数(例如用于分页)

sql - 具有挑战性的 Firebird 递归 CTE 问题

c# - Visual Studio 2015 中用于 Firebird 的 ADO.NET 数据提供程序

c# - NUnit 的 TestCaseAttribute 等效于 VS 单元测试框架

c# - 使用 HQL 查询从所有表而不是一个表中获取数据应该只获取 1 个表的数据

c# - 使用带有 WCF SOAP 的 XmlSerializer 添加根 xmlns

Java - C3P0 持有的连接数与 MySQL 中的 hibernate 连接数不匹配

servlets - 从 Sling/CQ 中的 bundle 获取 OSGi 服务