2014-09-26 78 views
2

我试图让SQLite运行在C#的Visual Studio 2012中。 但是,经过一组教程后,我仍然得到SQLite.Interop.dll错误DllNotFoundException。DllNotFoundException for SQLite.Interop.dll(C#&SQLite)

这是完全错误我收到:

无法加载DLL 'SQLite.Interop.dll':指定的路径 无效。 (异常来自HRESULT:0x800700A1)

我已经创建了System.Data.SQLite.dll的引用。现在我发现我必须将SQLite.Interop.dll文件添加到我的项目文件夹中,但仍然出现此错误。

哦,顺便说一句,这是我的代码,如果有人有兴趣:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Data.SQLite; 

namespace SQLiteWinFormCS 
{ 
public partial class Form1 : Form 
{ 

    private SQLiteConnection _sqlCon; 
    private SQLiteCommand _sqlCmd; 
    private SQLiteDataAdapter _db; 
    private DataSet _ds = new DataSet(); 
    private DataTable _dt = new DataTable(); 
    private string _dbPath = String.Empty; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void uiOpenDB_Click(object sender, EventArgs e) 
    { 
     Console(String.Format("You clicked {0}.", ((Button)sender).Name)); 
     this._dbPath = uiDatabaseFilepath.Text; 
     Console("Filepath to DB = " + this._dbPath); 

     Console("Attempting to open DB connection..."); 
     this._sqlCon = new SQLiteConnection(String.Format("Data Source={0};", @"\\Some-PC\ISC\Databases\testdbs\test.db3")); // << ERROR 
     Console("DB connection succesfull!"); 

    } 

    private void Console(string text) 
    { 
     uiConsoleOutput.AppendText(text); 
     uiConsoleOutput.ScrollToCaret(); 
    } 
} 
} 

谁能帮我把这个东西的工作?

在此先感谢。

回答

1

Dohh ...

我可能使用了错误的System.Data.SQLite.dll。

对于任何人谁是有兴趣,你可以找到新的.dll文件,我下载在这里: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

我所需要的.dll文件的4.5框架(86);我点击了第一个下载链接。

此外我只使用System.Data.SQLite.dll,没有其他文件!

希望此答案可以帮助别人。 :-)

2

将SQLite.Interop.dll文件复制到您的调试文件夹中。 例如“Projects \ sqlite test18 \ sqlite test18 \ bin \ Debug”放置在这里。

并且不添加Interop作为参考。

只添加这些引用

  • System.Data.SQLite
  • System.Data.SQLite.EF6
  • System.Data.SQLite.EF6

这解决了我的问题。 我在x64操作系统下使用Sqlite x86。