C#使用SQLite出錯:無法加載 DLL“SQLite.Interop.dll”,找不到指定的模塊


在SQLite官方下載了System.Data.SQLite,編寫如下測試代碼:

using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=F:\my.db;Pooling=true;FailIfMissing=false"))
{
    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter("select id,total from table1", conn))
    {
        DataTable table1 = new DataTable();
        adapter.Fill(table1);

        MessageBox.Show(table1.Rows[0]["total"].ToString());
    }
}


運行出錯,在new SQLiteConnection處提示:

引用內容
無法加載 DLL“SQLite.Interop.dll”: 找不到指定的模塊。 (異常來自 HRESULT:0x8007007E)。




解決方法

我下載的System.Data.SQLite版本是Precompiled Binaries for 32-bit Windows (.NET Framework 3.5 SP1),這個版本提供了兩個zip包:

①.sqlite-netFx35-binary-bundle-Win32-2008-1.0.79.0.zip

引用內容
This binary package features the mixed-mode assembly and contains all the binaries for the x86 version of the System.Data.SQLite 1.0.79.0 (3.7.10) package. The Visual C++ 2008 SP1 runtime for x86 and the .NET Framework 3.5 SP1 are required.


②.sqlite-netFx35-binary-Win32-2008-1.0.79.0.zip

引用內容
This binary package contains all the binaries for the x86 version of the System.Data.SQLite 1.0.79.0 (3.7.10) package. The Visual C++ 2008 SP1 runtime for x86 and the .NET Framework 3.5 SP1 are required.


我在項目引用的是第②個zip中的System.Data.SQLite.dll,運行出錯,改為引用第①個zip中的System.Data.SQLite.dll即可正常運行。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM