简体   繁体   中英

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:

SQL logic error or missing database
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.

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.

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. 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.

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." on the LoadExtension call even when it's actually there.

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). I just had to give it the name of the interop file and it worked:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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