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());
}
}
{
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即可正常运行。