System.Data.SQLite cannot load extension

I try to download the new json1 extension when establishing a connection, but I keep getting this error:

SQL logic error or missing database
The specified procedure was not 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 use NHibernate, so I just grab the connection from the session before executing any logic.

Is there something I'm doing wrong? I also tried loading SQLite.Interop.dll, and then called the sqlite3_json_init method and still does not work.

I did this and it still does not 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"); } 
+5
source share
2 answers

Actually, it doesn't seem like you need to enter the full path to the interop file. Apparently, it determines which processor architecture you are using and finds the SQLite.Interop.dll file in the bin folder based on this (bin / x64 / SQLite.Interop.dll). I just needed to give it the interop file name and it worked:

  SQLiteConnection connection = (SQLiteConnection)sender; connection.EnableExtensions(true); connection.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init"); 
+2
source

Downloading the extension from SQLite.Interop.dll is the correct way. Therefore, you should simply do the following:

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

I tested this and it works, so if you still have a problem, you may need to specify how you get the path to the interop file. For debugging purposes, perhaps add a statement before LoadExtension to make sure that the interop file you are trying to load actually exists where you think it is.

Also make sure that you are downloading the correct version (x86 vs. x64.) If you try to make a mistake, you will get: "The specified module could not be found." to call LoadExtension, even if it's actually there.

+3
source

Source: https://habr.com/ru/post/1247282/


All Articles