8

I'm trying to access a SpatiaLite from C# using System.Data.SQLite provider. When I try to load the SpatiaLite extension, I always get the

System.Data.SQLite.SQLiteException: SQLite error
The specified module could not be found.

error, even though the spatialite's dll has been copied to the bin directory. I even tried specifying the absolute path to the dll, but to no avail.

Here's the code:

string connectionString = @"Data Source=D:\MyStuff\projects\OsmUtils\trunk\Data\Samples\DB\osm.sqlite";
using (SQLiteConnection connection = new SQLiteConnection (connectionString))
{
    connection.Open();

    using (SQLiteCommand command = connection.CreateCommand())
    {
        command.CommandText = @"SELECT load_extension('libspatialite-1.dll');";
        command.ExecuteScalar();
    }
    ...

From this link I get the impression this should work.

Thanks in advance

Igor Brejc
  • 18,714
  • 13
  • 76
  • 95

2 Answers2

7

Well thanks to sqlite3.exe command line tool, I've found out that there are some additional DLLs needed for this to run:

  • libproj-0.dll
  • libgeos-3-1-1.dll
  • libgeos_c-1.dll

You can find these on SpatiaLite's download page. Just copy them to the bin directory.

UPDATE: one additional dll needed is libiconv2.dll

Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
  • copy to bin directory of the application or to the system folder? I can't get it work..any clues? – vinayan Nov 02 '12 at 07:28
  • @vinayan from what I remember, I added them as files to the C# project and then set their properties to "Copy if newer". So yes, they are in the bin directory of the application. – Igor Brejc Nov 02 '12 at 08:13
3

I had the exact same problem in Java. I called System.load() for all the dependent DLLs and everything worked like a champ!

  • libproj-0.dll
  • libgeos-3-1-1.dll
  • libgeos_c-1.dll
  • libiconv2.dll
  • libcharset1.dll
Peter
  • 1,182
  • 2
  • 12
  • 23