如何在 SQLite 中将事务隔离级别设置为 ReadUncommited?

发布于 2024-10-24 18:09:12 字数 1004 浏览 4 评论 0原文

根据此帖子的答案,它指出:

您是否知道,除非您启用了共享缓存并且两个连接都来自同一线程,否则 ReadUncomfilled 将恢复为序列化隔离?

然后,我使用 C# 继续定义 DLL 导入,如下所示:

[DllImport("System.Data.SQLite.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int sqlite3_enable_shared_cache(int enable);

我调用此函数来启用缓存,并在调用时获得成功结果状态 0。尽管如此,在执行以下行并尝试将隔离级别设置为 ReadUncommissed 时,我仍然收到异常“isolationlevel”。

string connectionString = @"data source=d:\db\test.db3;datetimeformat=Ticks";
SQLiteConnection conn = new SQLiteConnection(connectionString);
conn.Open();
IDbTransaction tran = conn.BeginTransaction(IsolationLevel.ReadUncommitted);

这个问题与我在这里发布的另一个问题相关

如何在 SQLite 中执行隔离级别为 ReadUncommissed 的查询?

According to the answer on this post it states:

Did you know that ReadUncommitted will revert to Serialized isolation unless you've enabled the shared cache and both connections are from the same thread?

Working in C#, I then went ahead and defined a DLL import as follows:

[DllImport("System.Data.SQLite.dll", CallingConvention=CallingConvention.Cdecl)]
public static extern int sqlite3_enable_shared_cache(int enable);

I called this function to enable the cache and got a successful result status of 0 when called. Nonetheless, I still get the exception "isolationlevel", when executing the below lines and attempting to set the isolation level to ReadUncommitted.

string connectionString = @"data source=d:\db\test.db3;datetimeformat=Ticks";
SQLiteConnection conn = new SQLiteConnection(connectionString);
conn.Open();
IDbTransaction tran = conn.BeginTransaction(IsolationLevel.ReadUncommitted);

This question is related to another question I posted here.

How can I pull off a query with an isolation level of ReadUncommitted in SQLite?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紅太極 2024-10-31 18:09:12

要完成未提交的读取,请参阅以下问题和答案:

如何在不锁定数据库的情况下使用数据读取器执行SQLite查询?

To accomplish uncommitted reads see the following question and answer:

How perform SQLite query with a data reader without locking database?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文