防止SQLITE完全关闭连接(C#)

发布于 2025-02-04 01:21:19 字数 531 浏览 1 评论 0原文

在WPF应用中,我正在创建与本地加密数据库(使用Microsoft.data.sqlite)的连接:

string builder = new SqliteConnectionStringBuilder($"Data Source=source.sqlite; Password='{password}';")
{
   Mode = SqliteOpenMode.ReadOnly
}.ToString();

每个查询都使用 block包裹在中。

问题在于,在应用程序上不活动5到10分钟之后,SQLite似乎可以关闭与数据库的连接,因为下一个查询需要至第一个查询(打开应用程序时,这是正常的,我想)。

我尝试使用sqliteconnectionstringbuilder的参数,例如cachepliming,但没有成功。

可以防止这种情况发生吗?

In a WPF app, I'm creating a connection to a local encrypted database (using Microsoft.Data.Sqlite):

string builder = new SqliteConnectionStringBuilder(
quot;Data Source=source.sqlite; Password='{password}';")
{
   Mode = SqliteOpenMode.ReadOnly
}.ToString();

Each query is wrapped in a using block.

The problem is that after 5 to 10 minutes of inactivity on the app, SQLite seems to close the connection to the database as the next query takes as long as the first one (when opening the app, which is normal, I guess).

I tried playing with the parameters of the SqliteConnectionStringBuilder such as Cache or Pooling, but no success.

Would it be possible to prevent this from happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文