在Visual Studio 2013的Windows上使用Mono.Data.Sqlite



编辑:好的,我注意到我更改了项目的输出文件夹并将DLL放入旧的输出文件夹中。将其放入正确的输出文件夹 Open() 后即可工作!我后来得到了另一个例外,但我想我可以解决这个问题......

我正在开发一个在Windows上的.NET和Linux/Mac上的Mono上运行的程序。我正在尝试向其添加一个非常简单的SQLite记录器。我将 Mono.Data.Sqlite.dll(Mono 3.10)添加到 Visual Studio 2013 中的项目引用中,并将 sqlite3.dll (http://www.sqlite.org/2014/sqlite-dll-win32-x86-3080701.zip) 复制到调试文件夹(创建程序 exe 的位置)。

这是我的测试代码:

using Mono.Data.Sqlite;
using System.Data;
namespace Program.Logging
{
    class MyLogger
    {
        public void TestMethod()
        {
            string connectionString = "URI=file:SqliteTest.db";
            IDbConnection dbcon;
            dbcon = (IDbConnection)new SqliteConnection(connectionString);
            dbcon.Open();
        }   
    }
}

但是当我尝试运行代码时,我在 dbcon 上收到此错误。打开():

类型为"System.EntryPointNotFoundException"的未处理异常 发生在Mono.Data.Sqlite.dll

附加信息: Der Einstiegspunkt "sqlite3_next_stmt" wurde nicht in der DLL "sqlite3" gefunden.(入口点 在 DLL "sqlite3" 中找不到"sqlite3_next_stmt"。

我做错了什么?

编辑:

string connectionString = "Data Source=file:SqliteTest.db";

类型为"System.ArgumentException"的未处理异常发生在 mscorlib.dll. 附加信息: URI-Formate werden nicht Unterstützt.(不支持 URI 格式。

string connectionString = "URI=file:SqliteTest.db,version3";

类型为"System.ArgumentException"的未处理异常发生在 Mono.Data.Sqlite.dll. 其他信息:无效的连接字符串 参数"版本3"的格式

您似乎使用了错误的连接字符串格式。 该文档指定了连接字符串格式:

[1.1 profile and the old assembly]
URI=file:/path/to/file
[2.0 profile in the new assembly]
Data Source=file:/path/to/file

由于您的目标是sqlite3,因此我想您应该使用2.0配置文件格式。

string connectionString = "Data Source=file:SqliteTest.db";

他们还提到,在 1.1 配置文件中,默认情况下使用 sqlite 版本 2,如果要使用旧格式,则必须指定版本。

string connectionString = "URI=file:SqliteTest.db,version=3";

最新更新