繁体   English   中英

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

[英]SQlite using statement gives Unable to load DLL 'SQLite.Interop.dll' error on another computer

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

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未找到SQLite.Interop.dll的异常。 我将System.Data.SQLite.dll添加到项目的引用中。 我在另一台计算机上也有此dll文件。 我需要添加任何东西到另一台计算机上以使该程序正常工作吗?

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

尝试检查connectionString,SQLite文件的位置,..也许您正在尝试在不允许您的程序在另一台计算机上写的地方创建它。 如果有区别,请尝试以管理员身份运行您的应用。 我唯一想到的是它在创建连接时崩溃,因此不会进入using语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM