在Firebird数据库上出现"Error MaxPoolSize"错误消息

4

关于数据库连接,我使用连接池和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

你尝试过4.1.0.0版本吗? - Mark Rotteveel
当我使用版本4.1.0.0时,出现了类似的错误“连接池已满”。 - Bartłomiej Pach
您没有处理您的FBCommand,这可能会阻止连接得到清理。 - Hans Passant
我修改了释放FBCommand的代码,但是我仍然有同样的错误。 - Bartłomiej Pach
代码不是真实的,因为例如zam变量未定义。 - cincura.net
显示剩余2条评论
2个回答

1
您的代码可能会导致异常并且永远无法到达Close(),从而保持连接打开状态,这可能会导致打开过多的连接。
您可能希望尝试在代码中实现Using()。 这里是一篇更详细描述的文章。 我曾经遇到类似的达到最大连接数的问题,使用Using()确实有所帮助。

1
当我在我的代码中使用Using()或者try, catch with finally时,我仍然遇到了类似的错误。 - Bartłomiej Pach
我已经失去了找到解决方案的希望。我的情况类似。我每15分钟重新启动应用程序,但我将尝试在池异常时使用FbConnection.ClearAllPools()。 - valentasm

0

尝试在IIS中回收您的连接池。您可以将其设置为每60分钟重置一次。这肯定会解决您的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接