简体   繁体   English

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

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

This is the code that I wrote for database connection: 这是我为数据库连接编写的代码:

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!");
            }
        }
    }`

When I run the program on the computer that I wrote the code it works properly and opens the database. 当我在编写代码的计算机上运行程序时,它可以正常工作并打开数据库。 However when I run my program in another computer code doesn't go into using statement and gives the exception SQLite.Interop.dll not found. 但是,当我在另一台计算机上运行程序时,代码不会进入using语句,并且会SQLite.Interop.dll未找到SQLite.Interop.dll的异常。 I added the System.Data.SQLite.dll to my project's references. 我将System.Data.SQLite.dll添加到项目的引用中。 Also I have this dll file in the other computer. 我在另一台计算机上也有此dll文件。 Do I need to add anything to the other computer to make this program work properly? 我需要添加任何东西到另一台计算机上以使该程序正常工作吗?

I figured it out that the problem was about SQLite dlls. 我发现问题出在SQLite dll上。 When I installed the System.Data.SQLite library from NuGet Package Manager and set the platform target as x86 problem resolved. 当我从NuGet程序包管理器安装System.Data.SQLite库并将平台目标设置为x86时,已解决问题。 Although platform target was x86 before I asked this question but re-installing the library from NuGet Package Manager solved my problem. 虽然在我问这个问题之前平台目标是x86,但是从NuGet Package Manager重新安装该库解决了我的问题。 Before that I was using the dlls I downloaded from the http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki as reference to my project. 在此之前,我使用从http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载的dll作为我的项目的参考。

Try to check the connectionString, the location of the SQLite file,.. Maybe you are trying to create it somewhere where your program is not allowed to write on the other computer. 尝试检查connectionString,SQLite文件的位置,..也许您正在尝试在不允许您的程序在另一台计算机上写的地方创建它。 Try to run your app as administrator if there is a difference. 如果有区别,请尝试以管理员身份运行您的应用。 The only thing that came on my mind is that it crashes at the moment of creating the connection and therefore it is not going into the using statement. 我唯一想到的是它在创建连接时崩溃,因此不会进入using语句。

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

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