c# - SQlite using 语句在另一台计算机上给出无法加载 DLL 'SQLite.Interop.dll' 错误

标签 c# database sqlite using using-statement

这是我为数据库连接编写的代码:

private static void OnTimedEvent(Object source, ElapsedEventArgs e)
{                       
        using (SQLiteConnection con = new SQLiteConnection(connectionString)) 
        {
            try
            {
                con.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            if (con.State == System.Data.ConnectionState.Open)
            {
                Console.WriteLine("Database Opened");

                ushort[] writeData = new ushort[10];
                writeData = parseList(byteList);

                if (writeData != errorBytes)
                {
                    writeToDb(con, writeData);
                }

                else
                {
                    Console.WriteLine("Error Bytes returned! BROKEN DATA!!!");
                }

                //con.Close();
            }

            else
            { 
                Console.WriteLine("Can't open the database!");
            }
        }
    }`

当我在我编写代码的计算机上运行该程序时,它可以正常工作并打开数据库。但是,当我在另一台计算机上运行我的程序时,代码不会进入 using 语句并给出异常 SQLite.Interop.dll not found。我将 System.Data.SQLite.dll 添加到我的项目引用中。我在另一台计算机上也有这个 dll 文件。我是否需要向另一台计算机添加任何内容才能使该程序正常运行?

最佳答案

我发现问题出在 SQLite dll 上。当我从 NuGet 包管理器安装 System.Data.SQLite 库并将平台目标设置为 x86 时,问题已解决。虽然在我问这个问题之前平台目标是 x86,但是从 NuGet 包管理器重新安装库解决了我的问题。在此之前,我使用的是从 http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki 下载的 dll。作为我项目的引用。

关于c# - SQlite using 语句在另一台计算机上给出无法加载 DLL 'SQLite.Interop.dll' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764189/

相关文章:

mysql - 如果某个项目出现超过 10 次,请将其删除并存储新的

c# - 无法将类型为 'System.DBNull' 的对象转换为类型 'System.String`

iphone - 如何从结果集中获取分组查询数据?

android - 在 OnClickListener 事件的数据库中插入多个值

c# - 引发事件或返回 bool 值?

c# - 为什么要使用 MVC 3 模板?

c# - Windows 8 应用程序中的 Windows 身份验证

c# - WCF 使用 AddressHeader.CreateAddressHeader() 方法添加 header 问题

php - MySQL统一ID相关查询优化

Python Sqlite 更新多个值