Running Sqlite on Mono

I am working on ac# 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.


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


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.

链接地址: http://www.djcxy.com/p/44588.html

上一篇: 设置非托管DLL加载目录

下一篇: 在Mono上运行Sqlite