System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: f2e586715f5cc53669171d8cc506f22841a71b7c
Title: Unable to enable extension loading in c#
Status: Closed Type: Question
Severity: Important Priority: Medium
Subsystem: Integration_Via_PInvoke Resolution: Unable_To_Reproduce
Last Modified: 2017-04-05 15:18:43
Version Found In: 1.0.104.0
User Comments:
anonymous added on 2017-04-04 12:43:29: (text/x-fossil-plain)
Dear system.data.sqlite developers,

as the titles spcifies I'm unable to load extensions (specifically mod_spatialite) in a C# project using system.data.sqlite. I get an "not authorized" error from SQLite as soon as I try to load mod_spatialite.

My code is as follows

String inputFile = "SomeDatabase.db";
dbConnection = "Data Source=" + inputFile;
CreateDataBase(inputFile);
connection = new SQLiteConnection(dbConnection);
connection.Open();
connection.SetConfigurationOption(SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, true);
connection.EnableExtensions(true);

SQLiteCommand version = new SQLiteCommand("SELECT sqlite_version();");  // this works fine
Console.WriteLine("SQLITE-Version: " + ExecuteScalar(version).ToString());  // returns "SQLITE-Version: 3.15.2"

SQLiteCommand loadSpatialite = new SQLiteCommand("SELECT load_extension('mod_spatialite');");
ExecuteNonQuery(loadSpatialite);  // crashes throwing a "not authorized"  message

ExecuteNonQuery() and ExecuteScalar() are consisting basically of the SQLiteCommand inside a try/catch block and setting the connection before executing)

Neither EnableExtensions(true) nor modifying the configuration options seems to show any effect.

At the same time, I can load mod_spatialite without any issues from the sqlite console. 

I of course tried with both, the pre-compiled binarys (VS2015, win64) and an own compile from the source.

(All compiles and dlls 64bit.)

connection.LoadExtension() does alwas return "specified module not found". This is does happen for Filename and absollute, as well as with relative Path, and with only the file name. 


Best,
Dominik

mistachkin added on 2017-04-04 20:15:53: (text/x-fossil-plain)
This type of question is better handled on the mailing list:

[/doc/trunk/www/support.wiki]

That being said, I think the issue MAY be a 32-bit versus 64-bit native binary
issue -OR- that the necessary native runtime(s) are not installed.

anonymous added on 2017-04-05 15:18:43: (text/x-fossil-plain)
Hi there!

The module not found was due to an architecture mismatch within a dependency, as you suspected correctly. Thanks for making me check!

However, I can definitely confirm, that I can load mod_spatialite with

MyConnection.LoadExtension("mod_spatilite");

no matter if

MyConnection.SetConfigurationOption(SQLiteConfigDbOpsEnum.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, true);
MyConnection.EnableExtensions(true);

are set to true or false.
At the same time,

SQLiteCommand loadSpatialite = new SQLiteCommand("SELECT load_extension('mod_spatialite');");

does never work (but used to do so in previous versions).

Best,
Dominik