0

I'm using SQLite as a means of moving data between a UI and a service but I've run into a few problems. I've looked around and I can't see anyone else with an issue like this. I've triple checked all my references, the x64 folder containing the Interop dll is included in the project, all these dlls are set to copy to the output directory, all directories have the right permissions and nothing's worked.

This is part of a larger problem I'm experiencing where if I use an SQLite Connection in my BackgroundWorker Completed function then the entire service crashes out with File not found exception, if I run an SQLite Connection inside the actual BackgroundWorker I get the Unable to load DLL 'SQLite.Interop.dll' error and finally if I use an SQLite Connection in a function that has no relation to a BackgroundWorker then it works perfectly (referencing this function from either BackgroundWorker event functions results in the same errors respectively).

Any help on this would be great

Code

Dim LiteUpdateString As String = ""
        Dim LiteConnection = New SQLiteConnection("Data Source=C:\...\AppData\Roaming\OPCService\Tags.db;Version=3;FailIfMissing=True")
        Dim LiteUpdate As String = ""
        UpdateNumber += 1
        teststring += UpdateNumber.ToString
        LiteUpdate = $"UPDATE SQLiteTags SET TagQuality='{teststring}' {SQLWhere}"
        Dim Command As New SQLiteCommand(LiteUpdate, LiteConnection)

        LiteConnection.Open()
        Command.ExecuteReader()
        LiteConnection.Close()

Errors

BackgroundWorkerCompleted

Application: OPCService.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException at OPCService.OPCService.BackgroundWorker1_RunWorkerCompleted(System.Object, System.ComponentModel.RunWorkerCompletedEventArgs) at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(System.ComponentModel.RunWorkerCompletedEventArgs) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch()

BackgroundWorker

Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

AdamBOD
  • 3
  • 5
  • 2
    can you show us the code? https://stackoverflow.com/help/mcve – vasek Jul 17 '17 at 09:51
  • Sorry about that, added now – AdamBOD Jul 17 '17 at 09:55
  • Can you post also full exception info? Btw, have you checked similar questions? https://stackoverflow.com/questions/13028069/unable-to-load-dll-sqlite-interop-dll or https://stackoverflow.com/questions/1278929/could-not-load-file-or-assembly-system-data-sqlite ? – vasek Jul 17 '17 at 09:58
  • Added the errors, I've followed all the steps in the links, been struggling with this for a few days now – AdamBOD Jul 17 '17 at 10:01
  • Have you tried to switch your project to x86? Same error? Does the same error appear if you create a new project and use NuGet to download SQLite package? https://www.nuget.org/packages/System.Data.SQLite – vasek Jul 17 '17 at 10:41
  • Switching to x86 even for testing would be quite a task as I have a lot of references compiled in x64, is there much chance of it actually helping in debugging? The package was downloaded with NuGet – AdamBOD Jul 17 '17 at 11:01
  • OK, then double check that your .exe directory contains `System.Data.SQLite.dll` and *none* of `SQLite.Interop.dll`s. Under this directory there should be `x64` directory, where is `SQLite.Interop.dll` in its 64-bit version. I had similar errors when some of x86/x64 files were in application directory. – vasek Jul 17 '17 at 11:07
  • Actually it might help you finding an error if you create a new project, switch to x86, add your problematic `BackgroundWorker` and see what happens. – vasek Jul 17 '17 at 11:08
  • Just checked and the Interops are only in the x64/x86 directories – AdamBOD Jul 17 '17 at 11:10
  • Same issue when compiled in x86 – AdamBOD Jul 17 '17 at 11:44

1 Answers1

0

I finally managed to find a somewhat workaround, since I can use SQLite in an independent function but can't call that function from a BackgroundWorker event thread, I start a timer once the thread is completed to execute the independent SQLite function.

AdamBOD
  • 3
  • 5