简体   繁体   English

System.Data.SQLite无法加载扩展

[英]System.Data.SQLite Can't Load Extension

I'm trying to load the new json1 extension when the connection in set up, but I keep receiving this error: 我正在尝试在设置连接时加载新的json1扩展,但我一直收到此错误:

SQL logic error or missing database SQL逻辑错误或缺少数据库
The specified procedure could not be found. 找不到指定的过程。

Here is my code: 这是我的代码:

SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
Assembly assembly = Assembly.Load("System.Data.SQLite");
connection.LoadExtension(assembly.Location, "sqlite3_json_init");

I'm using NHibernate, so I just grab the connection from the session before any logic is executed. 我正在使用NHibernate,所以我只是在执行任何逻辑之前从会话中获取连接。

Is there something I'm doing wrong? 有什么我做错了吗? I've also tried loading SQLite.Interop.dll and then calling the sqlite3_json_init method and that still does not work. 我也尝试加载SQLite.Interop.dll,然后调用sqlite3_json_init方法,但仍然无法正常工作。

I did this and it still doesn't seem to work: 我做了这个,它似乎仍然没有工作:

     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");
                }

Loading the extension from SQLite.Interop.dll is the correct way. 从SQLite.Interop.dll加载扩展是正确的方法。 So you should just be able to do the following: 所以你应该能够做到以下几点:

connection.EnableExtensions(true);
connection.LoadExtension(@"full\path\to\SQLite.Interop.dll", "sqlite3_json_init");

I've tested this and it's working, so if you still have a problem, you may need to indicate how you're getting the path of the interop file. 我已经测试了它并且它正在工作,所以如果你仍有问题,你可能需要说明你是如何获得互操作文件的路径的。 For debugging purposes, maybe add an assertion before LoadExtension to make sure the interop file that you're trying to load actually exists where you think it does. 出于调试目的,可能在LoadExtension之前添加一个断言,以确保您尝试加载的互操作文件实际存在于您认为的位置。

Also make sure that you're loading the correct version (x86 vs. x64.) If you try the wrong one, you'll get, "The specified module could not be found." 还要确保你正在加载正确的版本(x86与x64。)如果你尝试了错误的版本,你会得到,“找不到指定的模块。” on the LoadExtension call even when it's actually there. 在LoadExtension调用,即使它实际上在那里。

It actually looks like you do not need to enter in the full path to the interop file.. apparently it identifies which processor architecture you are using and finds the SQLite.Interop.dll file in the bin folder based on that (bin/x64/SQLite.Interop.dll). 它实际上看起来你不需要输入interop文件的完整路径..显然它确定你正在使用哪个处理器架构并在bin文件夹中找到SQLite.Interop.dll文件(bin / x64 / SQLite.Interop.dll)。 I just had to give it the name of the interop file and it worked: 我只需要给它interop文件的名称,它工作:

 SQLiteConnection connection = (SQLiteConnection)sender;
                connection.EnableExtensions(true);

                connection.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM