2

I'm using a PCL version of Sqlite.net from https://github.com/oysteinkrog/SQLite.Net-PCL This code below doesn't work for some reasons on WP8:

var sqliteFilename = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyDB.db3");
var db = new SQLiteConnection(new SQLitePlatformWP8CSharp(), sqliteFilename);

And I am receiving this error:

An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.DLL but was not handled in user code

Additional information: Could not open database file: C:\Data\Users\DefApps\AppData\{149B7F85-2C71-4BEF-984F-903BA7DB80DA}\Local\MyDB.db3 (CannotOpen)

What I am doing wrong? Thank you!!!

2 Answers 2

1

@Sergey-Chesalin thank you for your answers. I checked and found that it should create DB when it's not available. After my research I found why it doesn't work as it should.

For some reasons they add additional symbol to the connection string, see Line 121 in SQLiteConnection.cs and Line 196 in SQLiteConnection.cs. Maybe it works as expected in iOS/Android/WinRT versions of ISQLiteApi implementations, but it doesn't work as it should for Windows Phone.

So in order to fix it I have changed this line:

string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length);

To this:

string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length - 1);

in the SQLite.Net-PCL/blob/master/src/SQLite.Net.Platform.WindowsPhone8.CSharpSqlite/SQLiteApiWP8.cs line 12

Sign up to request clarification or add additional context in comments.

Comments

0

Have you marked your database file file as content in project? And you can explore deployed project with ISETool or something with GUI like this to check for file existence by this path.

3 Comments

I think that new DB must be created if it doesn't exists. Am I right?
@Sergey Original SQLite.net creates database when it's not available, but this fork uses different implementation, so you can check yourself and add source code of this library to your project and check what is happening in debugger. I have used different SQLite implementation. But SQLite is pretty slow if you need store big amounts of data. During optimization i found that reflection operations are abnormally slow on WP.
@Sergey maybe you can try different naming scheme for accessing isolated storage, because library uses Silverlight underneath not WP8 libraries. Two variants are: "isostore:/MyDB.db3" and "ms-appdata:///local/MyDB.db3"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.