简体   繁体   中英

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. I added the System.Data.SQLite.dll to my project's references. Also I have this dll file in the other computer. 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. When I installed the System.Data.SQLite library from NuGet Package Manager and set the platform target as x86 problem resolved. Although platform target was x86 before I asked this question but re-installing the library from NuGet Package Manager solved my problem. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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