I'm building a Windows 8 app, and now I want to use SQLite for this app. I installed SQLite for Windows Runtime
through the Visual Studio 2013 extension manager, and I added sqlite-net
to my project through NuGet.
I'm trying to create a database in my app.xaml.cs OnLaunched
, but I get this exception when I run the project:
Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
This is very strange because there is no error during compiling. Anyway, I think it tries to tell me that I need to reference an additional DLL: sqlite3.dll
, but that doesn't work. I have 6 different DLLs on my file system: both debug and release versions of ARM, x64 and x86. I tried adding the x86 release version to my project but that results in this exception:
A reference to 'C:\Users\Leon\Documents\Visual Studio 2013\Projects\Googalytics\packages\SQLite\x86\sqlite3.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
It's very sad that the documentation for sqlite-net sucks, it's very outdated (examples don't even work anymore), it's very incomplete and there is no mention of manually adding a DLL either. So I have 2 questions:
- How do I fix this particular issue?
- Where do I find up to date documentation for sqlite-net?
Edit: the code I use to create the DB is:
private void InitializeDatabase()
{
var db = new SQLiteConnection("Googalytics");
db.CreateTable<Account>();
db.CreateTable<WebProperty>();
db.CreateTable<Profile>();
}
I call that method from here:
InitializeDatabase();
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
edit2: some more info about my setup:
- Visual Studio 2013 RC
- Windows 8.1 RTM
- SQLite for Windows Runtime 3.8.0.2
- sqlite-net 1.0.7
Your project has its build mode currently set to Any CPU, what is the default. Because the SqLite assembly is not build as AnyCPU you need to set your build mode to X86 and add the X86 SqLite reference.
When deploying your app you also need to create 3 packages instead of 1 AnyCPU package.
Because your project is AnyCPU you get the error message when trying to add the x86, x86 is not valid for AnyCPU.
UPDATE
I tried to replicate your problem. I installed the
SQLite for Windows Runtime
for Visual Studio Ultimate 2012, after that I created a Windows Store Project, then added the SqLite reference after that I addedsqlite-net
and last I added your code for DB creation.I modified the code a little bit (path & tables). But my code gives no error at all.
I did not need to reference the SqLite assemblies myself. Because by installing the extension into Visual Studio you get the reference in your extension list (still need to select it, just not add the dlls):
But still like I said in my first answer, you need to set your build mode to something else than 'Any CPU'
My example is on my skydrive (when testing set configuration to x86).
UPDATE 2
Db path: