Getting a working SpatiaLite + SQLite system for x64 c#

China☆狼群 提交于 2019-11-30 12:47:19

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!