2014-09-26 70 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。