gpt4 book ai didi

c# - SQLite.Interop.dll 的 DllNotFoundException(C# 和 SQLite)

转载 作者:行者123 更新时间:2023-11-30 22:03:27 26 4
gpt4 key购买 nike

我正在尝试让 SQLite 在 Visual Studio 2012 for C# 中运行。但是,在学习了一组教程之后,我仍然收到 SQLite.Interop.dll 的错误 DllNotFoundException。

这是我收到的完整错误:

Unable to load DLL 'SQLite.Interop.dll': The specified path is invalid. (Exception from 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();
}
}
}

任何人都可以帮助我让这个东西工作吗?

提前致谢。

最佳答案

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

并且不要添加 Interop 作为引用。

仅添加这些引用

  • 系统.Data.SQLite
  • System.Data.SQLite.EF6
  • System.Data.SQLite.EF6

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

关于c# - SQLite.Interop.dll 的 DllNotFoundException(C# 和 SQLite),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26058179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com