2013-05-30 45 views
0

我有越來越SQLite的在我的C#IRC bot的工作問題。System.Data.Sqlite問題

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Data.SQLite; 
using System.IO; 

namespace ModBot 
{ 
class Database 
{ 
    private SQLiteConnection myDB; 
    private SQLiteCommand cmd; 

    public Database() 
    { 
     InitializeDB(); 
    } 

    private void InitializeDB() 
    { 
     if (File.Exists("ModBot.db")) 
     { 
      Console.WriteLine("HEYOOOOOOO"); 
      myDB = new SQLiteConnection("Data Source=ModBot.db;Version=3;"); 
      String sql = "CREATE TABLE IF NOT EXISTS twitch (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null);"; 
      cmd = new SQLiteCommand(sql, myDB); 
      cmd.ExecuteNonQuery(); 
     } 
     else 
     { 
      Console.WriteLine("YOOHOOOOO"); 
      SQLiteConnection.CreateFile("ModBot.db"); 
      myDB = new SQLiteConnection("Data Source=ModBot.db;Version=3;"); 
      String sql = "CREATE TABLE IF NOT EXISTS twitch (id INTEGER PRIMARY KEY, user TEXT, currency INTEGER DEFAULT 0, subscriber INTEGER DEFAULT 0, btag TEXT DEFAULT null);"; 
      cmd = new SQLiteCommand(sql, myDB); 
      cmd.ExecuteNonQuery(); 
     } 
    } 
} 
} 

我下載了System.Data.Sqlite,並將它作爲資源添加到我的項目中。當運行的代碼,它將引發DllNotFound異常(具體是:無法加載DLL「SQLite.Interop.dll」:指定的模塊找不到(從HRESULT異常:0x8007007E)),當它試圖使實際連接。

任何想法?

+0

你確定你的目標正確的平臺? http://stackoverflow.com/questions/4744293/unable-to-load-dll-sqlite3-the-specified-module-could-not-be-found-exceptio – wgraham

+0

您是否正確粘貼? – AAlferez

+0

@wgraham:我不確定如何使用Visual C#2010更改目標平臺。但我嘗試過使用x86和x64 SQLite dll。與任何一個相同的錯誤。 – Keirathi

回答

0
  1. 安裝RTM版本的Visual C++運行時庫與System.Data.SQLite 1.0.74完美協同工作。所以SP1版本是不需要的。

  2. 與.NET 4運行時一起安裝的C運行時版本是msvcr100的RTM版本,但名稱爲msvcr100_clr0400.dll。有了這個重命名爲msvcr100.dll的副本,無論是在System32中還是在System.Data.SQLite.dll旁邊,一切似乎都奏效。

  3. 他們似乎已經從C運行時的SxS部署搬走。因此,嵌入式清單中不再有'依賴項'標籤,並且無論System32中的最新版本(或與.exe相同的目錄)都將被加載。

有些哥們問了一個問題,在計算器上對這些變化:Visual C++ 2010: Changes to MSVC runtime deployment (no more SxS with manifest)

這一切都意味着你可以部署System.Data.SQLite.dll的.NET 4版和msvcr100.dll在同一目錄下,這是不可能與以前的版本運行的。對我來說,我的所有問題都可以解決,並且可以移至當前版本的System.Data.SQLite.dll。

+0

似乎沒有爲我工作,假設我做了你正確的建議。去到C:\ Windows \ System32 \,複製msvcr100_clr0400.dll,並將其放入與.exe相同的文件夾中,並將其重命名爲msvcr100.dll。 – Keirathi