I'm using this code to copy a SQLite DB to the device:
public static bool CopyEmbeddedDatabaseToWriteableDirectoryIfNeeded()
{
string filename = "Fruktose.db3";
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
if (!iso.FileExists(filename))
{
using (Stream source = Application.GetResourceStream(new Uri(Path.Combine("Assets", filename), UriKind.Relative)).Stream)
{
using (IsolatedStorageFileStream destination = iso.CreateFile(filename))
{
source.CopyTo(destination);
}
}
// get the full path of the created file
using (var file = iso.OpenFile(filename, FileMode.Open))
{
Debug.WriteLine(file.Name);
}
return true;
}
else
{
return false;
}
}
With this code I create a connection:
public SQLite.Net.SQLiteConnection GetConnection()
{
var plat = new SQLite.Net.Platform.WindowsPhone8.SQLitePlatformWP8();
return new SQLite.Net.SQLiteConnection(plat, DbPath);
}
private string DbPath
{
get { return Path.Combine(ApplicationData.Current.LocalFolder.Path, "Fruktose.db3"); }
}
But there I get a FileNotFoundException.
The Output Window of Visual Studio confirms that C:\Data\Users\DefApps\AppData{AC0B3218-28DE-47D1-AB68-E9638AE6A827}\Local\Fruktose.db3 exists.
DbPath points exactly to this file: C:\Data\Users\DefApps\AppData{AC0B3218-28DE-47D1-AB68-E9638AE6A827}\Local\Fruktose.db3.
I have exactly the same behavior on device and emulator.