I added what I thought were the necessary SQLite (and sqlite-net) packages to my app. On running it, though, I get an exception:
System.DllNotFoundException was unhandled by user code HResult=-2146233052 Message=Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from
I have the following SQLite packages installed:
What is missing?
I tried ajawad987's suggestion, but still get the same runtime error, even though I've got this:
...and this:
Where this runtime exception takes place (in SQLite.cs) seems odd to me:
var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);
// open using the byte[]
// in the case where the path may include Unicode
// force open to using UTF-8 using sqlite3_open_v2
var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
But I am using C#, so why is the line that's failing even running? (it fails in the "else" block)?
SQLite3. DLL is the dynamic-link library file containing the command-line tools used for managing the SQLite database. When you install an app that uses the SQLite database, the SQLite3. DLL is also automatically installed on your computer.
Install SQLite on Windows Step 1 − Go to SQLite download page, and download precompiled binaries from Windows section. Step 2 − Download sqlite-shell-win32-*. zip and sqlite-dll-win32-*. zip zipped files.
Is your project build set to Any CPU
? You'll need to set it to either x86
or x64
for SQLite3. The x86
route will yield more compatibility across devices, so I recommend that option unless your doing some specific 64-bit stuff.
Edit: You'll also need to download the actual Sqlite DLL manually from Sqlite's main site. The file you want is named sqlite-dll-win32-x86-3080702.zip
. Extract the DLL from that ZIP and add it to your project as a content file. Set the copy to output directory option in the properties tool window to Copy Always, and rebuild. Also ensure that your project is set to the x86 option as mentioned above.
This should hopefully do the trick... its been a while since I've used Sqlite in a .NET application.
Side Notes: The Nuget package you downloaded actually only contains the C# wrapper library around the real Sqlite DLL.
I had the same problem on a windows store app and i solved it by following this tutorial : http://www.c-sharpcorner.com/UploadFile/d351ba/working-with-sqlite-in-windows-store-apps/
No need to download manually the dll. The important step is the fifth :
5. Add references to the project.
Right-click on the References to the project under solution, select Add References. This opens up the Reference Manager of the project.
In the Reference Manager click on Windows Version. My application targets Windows 8.1 and therefore I have selected “Windows 8.1”. Select Extensions from the list as shown in the preceding screen shot. Now you will get the list of SDKs applicable to your project. As could be seen in the screen, SQLite for Windows Runtime (Windows 8.1) is available in the list post installation of SQLite from NuGet Package Installer.
Now check/tick the two options Microsoft Visual C++ 2013 Runtime Package for Windows 8.1 and SQLite for Windows Runtime (Windows 8.1) as shown in the screen shot. Then click “Ok”.
Check whether or not the references are added. You can see references are added but it is showing an exclamatory mark on these added references. If you build the application now you will get some warning messages along with the error messages in all certainty and the build fails with some messages as shown below. This is because the SQLite we have installed will not support the “Any CPU” processor architecture.
Now change the target platform from “Any CPU” to your CPU Architecture. In my case, the CPU Architecture is x64. The procedure to check your CPU architecture is specified below.
Not sure if this work for WPF app, but it worked for me on Windows store app. Click the link above for details and screenshots.
Hope this will help some people ;-)
In my case I just had to set project build to x86 or x64 AND set the target framework to 4. It doesn´t work with a higher framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With