Running Sqlite on Mono

13,010

Solution 1

It looks like it can't find the entry point in the native sqlite3 binary (sqlite3_open_v2). System.data.SQLLite is a managed ado.net wrapper that interops.

Do you also have the native sqlite3 binaries? They are located here: http://sqlite.org/download.html

EDIT:

Noticed you're using Mono and your download link below points to the windows dll download. Have tried looking at?

http://www.mono-project.com/SQLite

Solution 2

As your program is using a different .Net implementation of the SQLite client assemblies to the one you get included with mono, your new Assembly is calling an un-managed function that doesn't exist in the sqlite C library shipped with mono.

Mono ships by default with a config item to redirect the shared library used when asking for sqlite and sqlite3. This is usually in /etc/mono/config

Here is what I see on my machine:

    $ grep -i sqlite /etc/mono/config
    <dllmap dll="sqlite" target="libsqlite.so.0" os="!windows"/>
    <dllmap dll="sqlite3" target="libsqlite3.so.0" os="!windows"/>

This is described at http://www.mono-project.com/Config_DllMap.

You can create a config file to override the defaults defined for mono for your own program.

<!-- myprogram.exe.config -->
<configuration>
    <dllmap dll="sqlite3" target="./libsqlite3.so.0"/>
</configuration>

Note the ./ which forces the runtime to look in the same folder as the exe for the library.

If you decide to use a different version of Mono.Data.Sqlite than the one shipped with mono then you may still need to do this.

Share:
13,010
Boardy
Author by

Boardy

Develop apps and services in PHP, C#, C++, HTML, CSS, Jquery etc, recently started learning React.

Updated on June 04, 2022

Comments

  • Boardy
    Boardy almost 2 years

    I am working on a c# project which makes use of an SQLite3 database and needs to be cross compatible between windows and linux.

    The linux server is using version 3.2.8 and I am using the Managed Sqlite Library DLL 1.0.66.0.

    I have copied the DLL to the server and when I run mono myexec.exe it displays the following error

    Unhandled Exception: System.EntryPointNotFoundException: sqlite3_open_v2 at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods:sqlite3_open_v2 (byte[],intptr&,int,intptr) at System.Data.SQLite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool) [0x00000] in :0 at System.Data.SQLite.SQLiteConnection.Open () [0x00000] in :0 at AudioManagement.DatabaseConnection..ctor () [0x00000] in :0 at LinuxAudioManager.Configure.startConfiguration () [0x00000] in :0 at LinuxAudioManager.Program.Main (System.String[] args) [0x00000] in :0

    This error is thrown when it attempts to either make the database file or open the connection, I am not sure which one it is.

    Below is the code I am using in order create the connection

    conn = new SQLiteConnection("Data Source=database.db");
    conn.Open()
    

    Thanks for any help you can provide.

    UPDATE I have just executed my program with the mono logging and found something rather strange. Its seems to have a problem loading the lib file. The output is below

    Mono-INFO: DllImport attempting to load: 'libsqlite3.so.0'. Mono-INFO:

    DllImport loading location: 'libsqlite3.so.0.so'. Mono-INFO: DllImport

    error loading library: 'libsqlite3.so.0.so: cannot open shared object

    file: No such file or directory'. Mono-INFO: DllImport loading

    library: './libsqlite3.so.0.so'. Mono-INFO: DllImport error loading

    library './libsqlite3.so.0.so: cannot open shared object file: No such

    file or directory'. Mono-INFO: DllImport loading: 'libsqlite3.so.0'.

    Mono-INFO: Searching for 'sqlite3_open_v2'. Mono-INFO: Probing

    'sqlite3_open_v2'. Mono-INFO: Probing 'sqlite3_open_v2'. Mono-INFO:

    Probing 'sqlite3_open_v2A'. Mono-INFO: Probing 'sqlite3_open_v2A'.

    Mono-INFO: DllImport attempting to load: 'libsqlite3.so.0'. Mono-INFO:

    DllImport loading location: 'libsqlite3.so.0.so'. Mono-INFO: DllImport

    error loading library: 'libsqlite3.so.0.so: cannot open shared object

    file: No such file or directory'. Mono-INFO: DllImport loading

    library: './libsqlite3.so.0.so'. Mono-INFO: DllImport error loading

    library './libsqlite3.so.0.so: cannot open shared object file: No such

    file or directory'. Mono-INFO: DllImport loading: 'libsqlite3.so.0'.

    Mono-INFO: Searching for 'sqlite3_open_v2'. Mono-INFO: Probing

    'sqlite3_open_v2'. Mono-INFO: Probing 'sqlite3_open_v2'. Mono-INFO:

    Probing 'sqlite3_open_v2A'. Mono-INFO: Probing 'sqlite3_open_v2A'.

    The file libsqlite3.so.0 does exist but I can't see why mono is then attempting to load libsqlite3.so.0.so.

    UPDATE 2 I think the first update error messages were pointing me in the wrong direction as I have created a symlink to match where it couldn't find the lib file and mono is no longer saying that it couldn't load something. However the original EntryPointNotFoundException is still displayed

    UPDATE 3 Thanks to @bryanmac I have changed the code to use the Mono.Data.Sqlite dll instead which works fine on Linux under mono. However, using this DLL in Windows is now no longer working. VS2010 will build it without problems but when I try to execute it it will display the error

    Unable to load DLL 'sqlite3': The specified module could not be found

    I have downloaded an sqlite3.exe binary from the sqlite website and the executable to the executable of my program but my program still displays the error message on Windows.

  • Boardy
    Boardy over 12 years
    I have tried the managed and non managed but they both seem to come up with the same error message
  • bryanmac
    bryanmac over 12 years
    When you use the managed one are the sqlite3 binaries from the download location I specified, sitting side by side with them?
  • bryanmac
    bryanmac over 12 years
    They have a managed and unmanaged wrapper layers that interop with the native sqlite.org binaries ...
  • Boardy
    Boardy over 12 years
    No they are from sourceforge.net/projects/sqlite-dotnet2/files/… I've download both the managed only binaries and normal binaries. From the link you provided I am not sure which one to try and download
  • Boardy
    Boardy over 12 years
    Thanks for all your help with this. Please see update 3, it now works in Linux but not in Windows.
  • Boardy
    Boardy over 12 years
    Sorry I don't understand what this does. At the moment it is now working in Linux under mono without problem. The problem is now with Windows saying that it can't find the module. Sorry if I am being a bit of a noob I am very new to using Sqlite on linux and windows
  • Boardy
    Boardy over 12 years
    Thanks for your help with this. I have managed to get it working on both Linux thanks to your answer and on Windows now as well. I was able to find the sqlite3.dll to put with my program so it now works fine in both windows and linux