0
SqLite的連接字符串可以包含使用連接池的選項,例如(僞代碼)如何在C#或VB.NET中使用SqLite連接池?
Dim connectionString = "Data Source=" + Path + ";" +
"Version=3;" +
"Pooling=True;" +
"Max Pool Size=100;"
我認爲有一些額外的類或工廠方法使用連接池,例如,
dim connectionPool = new SqLiteConnectionPool(connectionString)
dim firstConnection = connectionPool.getConnection()
...
firstConnection.dispose()
...
dim secondConnection = connectionPool.getConnection()
但是,我找不到這樣的班級。
=>如何返回到連接池的連接?
=>如何重新使用先前已返回到池的連接?
在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)
傳遞連接字符串幾次似乎並不直觀我。
b)或者我只會創建連接一次,並在關閉/處理後將其喚醒?
dim connection = new SqLiteConnection(connectionString))
using connection
...
end using
connection.open()
using connection
...
end using
我有一箇中風或是這個代碼是C#和VB的奇怪組合嗎? – maccettura
可能是。 :)只是一些僞代碼,以更好地解釋我的問題。 – Stefan
我想它的工作方式與SQL Server連接池相同。如果啓用了池化,關閉/處置打開的連接會將其返回到池而不是關閉到服務器的連接。因此,您應該簡單地在一個使用塊中打開您的連接,以確保在完成時處理它,即使發生異常也是如此。 – Joe