[英]Encrypted SQLite database can't be opened with System.Data.SQLite
[英]System.Data.SQLite Can't Load Extension
我正在尝试在设置连接时加载新的json1扩展,但我一直收到此错误:
SQL逻辑错误或缺少数据库
找不到指定的过程。
这是我的代码:
SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
Assembly assembly = Assembly.Load("System.Data.SQLite");
connection.LoadExtension(assembly.Location, "sqlite3_json_init");
我正在使用NHibernate,所以我只是在执行任何逻辑之前从会话中获取连接。
有什么我做错了吗? 我也尝试加载SQLite.Interop.dll,然后调用sqlite3_json_init
方法,但仍然无法正常工作。
我做了这个,它似乎仍然没有工作:
SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
string path = "F:\\GitHub\\ExampleProj\\lib\\sqlite\\SQLite.Interop.dll";
if (File.Exists(path))
{
connection.LoadExtension(path,
"sqlite3_json_init");
}
从SQLite.Interop.dll加载扩展是正确的方法。 所以你应该能够做到以下几点:
connection.EnableExtensions(true);
connection.LoadExtension(@"full\path\to\SQLite.Interop.dll", "sqlite3_json_init");
我已经测试了它并且它正在工作,所以如果你仍有问题,你可能需要说明你是如何获得互操作文件的路径的。 出于调试目的,可能在LoadExtension之前添加一个断言,以确保您尝试加载的互操作文件实际存在于您认为的位置。
还要确保你正在加载正确的版本(x86与x64。)如果你尝试了错误的版本,你会得到,“找不到指定的模块。” 在LoadExtension调用,即使它实际上在那里。
它实际上看起来你不需要输入interop文件的完整路径..显然它确定你正在使用哪个处理器架构并在bin文件夹中找到SQLite.Interop.dll文件(bin / x64 / SQLite.Interop.dll)。 我只需要给它interop文件的名称,它工作:
SQLiteConnection connection = (SQLiteConnection)sender;
connection.EnableExtensions(true);
connection.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.