Getting a working SpatiaLite + SQLite system for x64 c#
Asked Answered
T

3

10

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?

Tradeswoman answered 26/3, 2014 at 16:56 Comment(0)
S
2

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:

  1. libsqlite3-0.dll
  2. libgeos-3-0-2.dll
  3. libgeos-c-1.dll
  4. libiconv2.dll
  5. libproj-0.dll
  6. libvirtualtext-2.dll
  7. 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
Supplejack answered 8/4, 2014 at 12:19 Comment(0)
T
2

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();
                }
Turner answered 8/4, 2015 at 10:10 Comment(1)
So I found the problem. If this code still doesn't work its because mod_spatialite ships with the wrong libstdc++_64-6.dll. Work around here. blog.jrg.com.br/2016/04/25/Fixing-spatialite-loading-problemArrowood
R
1

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

Rucker answered 31/5, 2017 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.