Running Sqlite on Mono

I am working on a C # project that uses a SQLite3 database and needs to be cross-compatible between windows and linux.

The linux server uses version 3.2.8, and I use the Sqlite DLL 1.0.66.0 managed library.

I 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 (native-managed wrapper) System.Data.SQLite.UnsafeNativeMethods: sqlite3_open_v2 (byte [], intptr &, int, intptr) in System.Data.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite.SQLite. String strFilename, flags SQLiteOpenFlagsEnum, Int32 maxPoolSize, Boolean usePool) [0x00000] at: 0 at System.Data.SQLite.SQLiteConnection.Open () [0x00000] at: 0 on AudioManagement.DatabaseConnection..ctor () [0x00000] at: 0 on LinuxAudioManager.Configure.startConfiguration () [0x00000] at: 0 on LinuxAudioManager.Program.Main (System.String [] args) [0x00000] at: 0

This error occurs when trying to make a database file or open a connection, I'm not sure what it is.

Below is the code that I use to create the connection

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

Thanks for any help you can provide.

UPDATE I just ran my mono-recording program and found something rather strange. It seems to have a problem loading the lib file. Output below

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

The place to download DllImport is 'libsqlite3.so.0.so'. Mono-INFO: DllImport

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

file: There is no such file or directory '. Mono-INFO: loading DllImport

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

library './libsqlite3.so.0.so: cannot open file of shared objects: such

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

Mono-INFO: search for "sqlite3_open_v2". Mono-INFO: Research

'sqlite3_open_v2'. Mono-INFO: study "sqlite3_open_v2". Mono-INFO:

Research "sqlite3_open_v2A". Mono-INFO: Study "sqlite3_open_v2A".

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

The place to download DllImport is 'libsqlite3.so.0.so'. Mono-INFO: DllImport

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

file: There is no such file or directory '. Mono-INFO: loading DllImport

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

library './libsqlite3.so.0.so: cannot open file of shared objects: such

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

Mono-INFO: search for "sqlite3_open_v2". Mono-INFO: Research

'sqlite3_open_v2'. Mono-INFO: study "sqlite3_open_v2". Mono-INFO:

Research "sqlite3_open_v2A". Mono-INFO: Study "sqlite3_open_v2A".

The libsqlite3.so.0 file exists, but I cannot understand why mono is trying to download libsqlite3.so.0.so.

UPDATE 2 I think the first update error messages were pointing me in the wrong direction, as I created a symbolic link to match where it could not find the lib file, and mono no longer says that it cannot load something . However, the original value of EntryPointNotFoundException is still displayed

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

Unable to load DLL 'sqlite3': the specified module was not found

I downloaded the sqlite3.exe binary from the sqlite site and the executable to my program's executable, but my program still displays an error message in Windows.

+4
source share
2 answers

It seems like he cannot find the entry point in the sqlite3 source binary (sqlite3_open_v2). System.data.SQLLite is an ado.net-driven shell that intercepts.

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

EDIT:

I noticed that you are using Mono, and your download link below indicates the loading of windows dll. Have you tried to see?

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

+1
source

Because your program uses a different .Net implementation of SQLite client assemblies for the one you include in mono, your new assembly calls an unmanaged function that does not exist in the sqlite C library that comes with mono.

Mono sends the default configuration item to redirect the shared library used when querying sqlite and sqlite3. This is usually found 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 configuration file to override the default values ​​defined for mono for your own program.

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

Pay attention to ./ , which causes the working environment to search in the same folder as exe for the library.

If you decide to use a different version of Mono.Data.Sqlite than the one that comes with mono, you still have to do it.

+4
source

Source: https://habr.com/ru/post/1390416/


All Articles