如何在 C# 或 VB.NET 中使用 Sqlite 连接池?

Ste*_*fan 3 c# sqlite connection-pooling

Sqlite 的连接字符串可以包括使用连接池的选项,例如(伪代码)

Dim connectionString = "Data Source=" + Path + ";" +
                                    "Version=3;" +
                                    "Pooling=True;" +
                                    "Max Pool Size=100;"
Run Code Online (Sandbox Code Playgroud)

我希望有一些额外的类或工厂方法来使用连接池,例如

dim connectionPool = new SqLiteConnectionPool(connectionString)

dim firstConnection = connectionPool.getConnection()
...
firstConnection.dispose()

...
dim secondConnection = connectionPool.getConnection()
Run Code Online (Sandbox Code Playgroud)

但是,我找不到这样的课程。

=>如何返回连接池的连接

=>如何重用以前返回到池中的连接

https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki上搜索“pool”没有给出任何结果。

a) 我是否必须多次调用连接的构造函数?

dim firstConnection = new SqLiteConnection(connectionString)
...
firstConnection.dispose()


dim secondConnection = new SqLiteConnection(connectionString)
Run Code Online (Sandbox Code Playgroud)

多次传递连接字符串对我来说似乎并不直观。

b) 或者我会只创建一次连接并在它关闭/处置后以某种方式唤醒它?

dim connection = new SqLiteConnection(connectionString))
using connection 
 ...
end using 

connection.open()
using connection
 ...
end using 
Run Code Online (Sandbox Code Playgroud)

小智 5

SQLite 驱动程序将为您管理池,但是,在使用连接时,许多人没有意识到一个关键点。

晚开,早关

如果连接处于打开状态,则连接无法返回到池中。因此,您可以创建连接,准备语句,但是,只能在执行查询之前立即打开连接。