I need to create and access a spatialite-extended SQLite database under x64 windows.
I have downloaded the latest version 1.0.92.0 called sqlite-netFx45-static-binary-bundle-x64-2012-1.0.92.0.zip
of System.Data.SQLite. It is referenced from my Visual Studio (2012) project, and seems to work just fine by itself.
I also have the latest precompiled x64 spatiaLite version 4.1.1 called spatialite-4.1.1-DLL-win-amd64.zip All the dlls from spatialite are present in the executing directory.
When I try to load the extension:
using (var conn = new SQLiteConnection("Data Source=\"" + _sqLiteFullName + "\""))
{
conn.Open();
conn.EnableExtensions(true);
conn.LoadExtension("libspatialite-4.dll");
...
}
I get an AccessViolationException (Attempted to read protected memory. This is often an indication that other memory is corrupt) on the LoadExtension()
line.
I notice when looked at with PE Deconstructor (software that determines the bitnewss of dll/exe), it says that my copy of System.Data.SQLite.dll (from the x64 package) is actually 32bits. Is that the problem?
How to I remedy this?
How has anyone else got spatiaLite working on x64?
Actually, the problem could be in spatialite-4.dll this autmun I spent a week trying to fix the same issue without success. It looks like that there problems in spatialite-4.dll (I mean this one downloaded form gaia-sins (official spatialite site) ) You can try to build a Spatialite from sources (like a nightmare (: ) or try to look for another build of .dll. Second option helped me. Btw, there a couple of .dlls you need to use Spatialite extension:
- libsqlite3-0.dll
- libgeos-3-0-2.dll
- libgeos-c-1.dll
- libiconv2.dll
- libproj-0.dll
- libvirtualtext-2.dll
- libspatialite-2.dll <----- Spatialite v.2 completely suits my project. As I told, if you need v.4 you can try to build it or look for a another build. Hope, this helps
download mod_spatialite from the site, choose mod_spatialite-4.2.0-win-amd64.7z. unzip and copy all dll to the bin folder of your program.
sample code:
//SELECT load_extension("mod_spatialite") // doesn't need the '.dll' suffix.
using (var cnn = new SQLiteConnection(connStr))
{
//connStr = "FullUri=file::memory:?cache=shared;Pooling=True;Max Pool Size=200;";
cnn.Open();
//cnn.EnableExtensions(true);
using (SQLiteCommand mycommand = new SQLiteCommand("SELECT load_extension(\"mod_spatialite\")", cnn))
{
mycommand.ExecuteNonQuery();
}
Have a look in this Google Groups discussion here:
https://groups.google.com/forum/#!topic/spatialite-users/u2QZpQL_6ek
The latest solution is by Dominik:
I just found out, that the hack described at http://blog.jrg.com.br/2016/04/25/Fixing-spatialite-loading-problem/ only works with the dlls from the second most recent version of mingw64
mingw-w64-bin_x86_64-linux_20131228.tar.bz2 from http://netassist.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Automated%20Builds/mingw-w64-bin_x86_64-linux_20131228.tar.bz2.
Any attempt to do the same with the most recent version available at sourcefourge http://sourceforge.net/projects/mingw-w64/files/latest/download failed on my system.However, I can definitely confirm, that I can load mod_spatialite with
MyConnection.LoadExtension("mod_spatilite");
来源:https://stackoverflow.com/questions/22667981/getting-a-working-spatialite-sqlite-system-for-x64-c-sharp