Linux 在 Mono 上运行 Sqlite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8819083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Sqlite on Mono
提问by Boardy
I am working on a c# project which makes use of an SQLite3 database and needs to be cross compatible between windows and linux.
我正在研究 ac# 项目,该项目使用 SQLite3 数据库并且需要在 windows 和 linux 之间交叉兼容。
The linux server is using version 3.2.8 and I am using the Managed Sqlite Library DLL 1.0.66.0.
linux 服务器使用的是 3.2.8 版,我使用的是托管 Sqlite 库 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
我已将 DLL 复制到服务器,当我运行 mono myexec.exe 时,它显示以下错误
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
未处理的异常: System.EntryPointNotFoundException: sqlite3_open_v2 at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods:sqlite3_open_v2 (byte[],intptr&,int,intptr) 在 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.
感谢您的任何帮助,您可以提供。
UPDATEI 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
更新我刚刚用单声道日志执行了我的程序,发现了一些很奇怪的东西。加载lib文件似乎有问题。输出如下
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'.
Mono-INFO:DllImport 试图加载:'libsqlite3.so.0'。单信息:
DllImport 加载位置:'libsqlite3.so.0.so'。Mono-INFO:DllImport
错误加载库:'libsqlite3.so.0.so:无法打开共享对象
文件:没有这样的文件或目录'。Mono-INFO:DllImport 加载
库:'./libsqlite3.so.0.so'。Mono-INFO:DllImport 错误加载
库'./libsqlite3.so.0.so:无法打开共享对象文件:没有这样的
文件或目录”。Mono-INFO:DllImport 加载:'libsqlite3.so.0'。
Mono-INFO:搜索“sqlite3_open_v2”。Mono-INFO:探测
'sqlite3_open_v2'。Mono-INFO:探测“sqlite3_open_v2”。单信息:
探测'sqlite3_open_v2A'。Mono-INFO:探测“sqlite3_open_v2A”。
Mono-INFO:DllImport 试图加载:'libsqlite3.so.0'。单信息:
DllImport 加载位置:'libsqlite3.so.0.so'。Mono-INFO:DllImport
错误加载库:'libsqlite3.so.0.so:无法打开共享对象
文件:没有这样的文件或目录'。Mono-INFO:DllImport 加载
库:'./libsqlite3.so.0.so'。Mono-INFO:DllImport 错误加载
库'./libsqlite3.so.0.so:无法打开共享对象文件:没有这样的
文件或目录”。Mono-INFO:DllImport 加载:'libsqlite3.so.0'。
Mono-INFO:搜索“sqlite3_open_v2”。Mono-INFO:探测
'sqlite3_open_v2'。Mono-INFO:探测“sqlite3_open_v2”。单信息:
探测'sqlite3_open_v2A'。Mono-INFO:探测“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.
文件 libsqlite3.so.0 确实存在,但我不明白为什么 Mono 会尝试加载 libsqlite3.so.0.so。
UPDATE 2I 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
更新 2我认为第一条更新错误消息指向了错误的方向,因为我创建了一个符号链接来匹配它找不到 lib 文件的地方,并且 mono 不再说它无法加载某些东西。但是仍然显示原始的 EntryPointNotFoundException
UPDATE 3Thanks 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
更新 3感谢@bryanmac,我已经更改了代码以使用 Mono.Data.Sqlite dll 代替它在 Linux 下的 Mono 上运行良好。但是,在 Windows 中使用此 DLL 现在不再有效。VS2010 可以毫无问题地构建它,但是当我尝试执行它时,它会显示错误
Unable to load DLL 'sqlite3': The specified module could not be found
无法加载 DLL 'sqlite3':找不到指定的模块
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.
我已经从 sqlite 网站下载了一个 sqlite3.exe 二进制文件并将可执行文件下载到我的程序的可执行文件中,但我的程序仍然在 Windows 上显示错误消息。
采纳答案by bryanmac
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.
看起来它在原生 sqlite3 二进制文件 (sqlite3_open_v2) 中找不到入口点。System.data.SQLLite 是一个可互操作的托管 ado.net 包装器。
Do you also have the native sqlite3 binaries? They are located here: http://sqlite.org/download.html
你也有原生的 sqlite3 二进制文件吗?它们位于: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?
注意到您正在使用 Mono 并且您下面的下载链接指向 Windows dll 下载。有没有试过看?
回答by IanNorton
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.
由于您的程序使用的 SQLite 客户端程序集的 .Net 实现与您包含在单声道中的程序不同,因此您的新程序集正在调用一个非托管函数,该函数在单声道附带的 sqlite C 库中不存在。
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
Mono 默认带有一个配置项,用于重定向请求 sqlite 和 sqlite3 时使用的共享库。这通常在/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.
这在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.
请注意./
这会强制运行时在与库的 exe 相同的文件夹中查找。
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.
如果您决定使用与 Mono 附带的版本不同的 Mono.Data.Sqlite 版本,那么您可能仍然需要这样做。