FirebirdClient 中的连接池似乎已损坏。它应该在我的查询已经为空时排队,但我得到了一个异常。我需要帮助如何处理这个问题。
我正在使用 FirebirdClient 版本 7.1.1。我正在运行一个控制台 .Net Core 应用程序(版本 2.2.0)并且我正在连接 Firebird 3.0。我执行 4 个并发查询。我将 MaxPoolSize 设置为 2。因此没有足够的连接来执行所有查询。
using System;
using System.Threading.Tasks;
using FirebirdSql.Data.FirebirdClient;
namespace ConsoleApp3
{
class Program
{
private const string connStr =
"User=SYSDBA;Password=***;Database=/opt/firebird/bases/db.fdb;DataSource=192.168.2.1;Port=3050;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=2;";
private static void Connect(string name)
{
Console.WriteLine($">>>>>>STARTING>>>>>>>>>>>> {name}");
var cmd = new FbCommand(
"select count(*) from MON$ATTACHMENTS a where a.mon$remote_process like '%ConsoleApp3.dll'");
using (cmd.Connection = new FbConnection(connStr))
{
try
{
cmd.Connection.Open();
var id = Convert.ToInt32(cmd.ExecuteScalar());
Task.Delay(1000);
Console.WriteLine($">>>>>>Done>>>>>>>>>>>> {name} RESULT {id}");
}
catch (Exception e)
{
Console.WriteLine($">>>>>>>ERROR>>>>>>>>>>> {name}");
Console.WriteLine(e);
}
}
}
static void Main(string[] args)
{
var t1 = Task.Run(() => Connect("conn1"));
var t2 = Task.Run(() => Connect("conn2"));
var t3 = Task.Run(() => Connect("conn3"));
var t4 = Task.Run(() => Connect("conn4"));
Task.WaitAll(t1, t2, t3, t4);
Console.WriteLine(">>>>>>>>>>>> DONE>>>>>>>>>>>>>>>");
Console.ReadKey();
}
}
}
我希望当与数据库的连接将被回收到连接池时,没有空闲连接的查询将排队并执行,但我得到以下异常:
System.InvalidOperationException: Connection pool is full.
at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.CreateNewConnectionIfPossibleImpl(ConnectionString connectionString)
at FirebirdSql.Data.FirebirdClient.FbConnectionPoolManager.Pool.GetConnection(FbConnection owner)
at FirebirdSql.Data.FirebirdClient.FbConnection.Open()
at ConsoleApp3.Program.Connect(String name) in C:\Projects\ConsoleApp3\ConsoleApp3\Program.cs:line 22