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