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

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

问题描述:

编辑:好的,我注意到我更改了项目的输出文件夹,并将该DLL放入旧的输出文件夹中。将它放在正确的输出文件夹Open()中后!我以后得到另一个异常,但我想我可以修复...在Visual Studio 2013的Windows上使用Mono.Data.Sqlite

我正在运行在Windows上和在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.Open()得到这个错误:

型系统的”未处理的异常。 EntryPointNotFoundException” 发生在Mono.Data.Sqlite.dll

其他信息:明镜Einstiegspunkt “sqlite3_next_stmt” 在德DLL “sqlite3的” gefunden wurde nicht。 (入口点 “sqlite3_next_stmt” 没有在DLL “sqlite3的” 发现。)

我在做什么错?

编辑:

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。附加信息:无效ConnectionString 参数“version3”的格式

看起来您使用了错误的连接字符串格式。该documentation指定连接字符串格式:

[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配置文件,任何版本2默认情况下使用,你就必须指定版本,如果你想,如果你使用旧格式使用。

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

我已经尝试了建议的连接字符串的两个版本,他们都抛出不同的例外。 – John 2014-11-14 17:40:58

+0

对不起,第二个版本有一个错字,应该有'version = 3'。 – 2014-11-14 18:03:54

+0

我没有在正确的输出文件夹中的DLL。我之前更改了输出文件夹并忘记了它,并将该DLL放入旧文件夹中... – John 2014-11-14 18:04:48