简体   繁体   中英

In Windows Phone 8, SQLite works but doesn't write the database file to IsoStore

My app is using sqlite-net-wp8 for Windows Phone 8 to manage a local database.

It seems that the database file is never written to IsoStore (as seen with IsoStoreSpy ). No exceptions are thrown.

I have tried the following:

  • Upgrading SQLite for Windows Phone from 3.7.1.16 to 3.8.0.2 (an extremely painful process)

  • Providing absolute and relative paths as suggested in Working with sqlite in windows phone 8 a sqlite net version for mobile .

     SQLite.SqliteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, filename)) SQLite.SqliteConnection(filename) 
  • Providing SQLiteOpenFlags explicitly to the SQLite.SQLiteConnection

  • Other random things

Here is my code (I am using USE_WP8_NATIVE_SQLITE )

string filename = "data.db";
string seqStr = "CREATE TABLE ...";
using (SQLiteConnection db = new SQLite.SQLiteConnection(filename, 
    SQLiteOpenFlags.Create | SQLiteOpenFlags.ReadWrite, true))
{
    db.BeginTransaction();
    db.Execute(seqStr);
    db.Commit();
    db.Close();
}

I have run out of ideas. If someone can help me, I would be really grateful.

Finally, solved!

You are right, db.Close() is redundant (the Dispose will call the Close() function.

My non-working code:

string filename = "Data Source=" + "data.db" + ";Version=3;New=False;Compress=True;"

My now working code:

string filename = Path.Combine(ApplicationData.Current.LocalFolder.Path, "data.db");

One small roadblock removed, many more to go!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM