我一直认为最好使用和关闭数据库连接。但是对于 SQLite,我不确定这是否适用。我使用 Using Connection 语句执行所有查询。所以我的理解是我打开一个连接然后关闭它这样做。当谈到 SQLite 和最佳使用时,是在程序使用期间打开一个永久连接还是继续使用我目前使用的方法更好。
我正在将数据库用于 VB.net windows 程序,该程序具有大约 2gig 的相当大的 DB。
我目前的连接方法示例
Using oMainQueryR As New SQLite.SQLiteCommand
oMainQueryR.CommandText = ("SELECT * FROM CRD")
Using connection As New SQLite.SQLiteConnection(conectionString)
Using oDataSQL As New SQLite.SQLiteDataAdapter
oMainQueryR.Connection = connection
oDataSQL.SelectCommand = oMainQueryR
connection.Open()
oDataSQL.FillSchema(crd, SchemaType.Source)
oDataSQL.Fill(crd)
connection.Close()
End Using
End Using
End Using
Run Code Online (Sandbox Code Playgroud)