【发布时间】:2015-11-05 10:58:43
【问题描述】:
我正在寻找一种在使用 SQLite 的 System.Data.SQLite 包装器时启用 shared cache mode 的方法。
我查看了该项目的源代码,发现它在 UnsafeNativeMethods.cs 中的程序集内部公开为:
internal static extern SQLiteErrorCode sqlite3_enable_shared_cache(
int enable);
很遗憾,我无法使用这种方法,因为它是内部的。
有人有解决办法吗?
非常感谢您的回复。谢谢!
仅供参考,使用 SQLiteConnectionStringBuilder API 时,请通过以下方式启用共享缓存:
var builder = new SQLiteConnectionStringBuilder();
...
builder.Add("cache", "shared");
【问题讨论】:
-
给其他人的注意事项:所有连接都必须在连接字符串中具有“cache=shared”设置,以便它们连接到实际的共享缓存,否则它们将简单地创建自己的。此外,为了使这适用于内存数据库,conn 字符串中也需要一个“mode=memory”,即
FullUri=file:demo?mode=memory&cache=shared;。
标签: c# sqlite system.data.sqlite