在Windows Phone 8中,SQLite可以工作,但不会将数据库文件写入IsoStore

时间:2013-09-06 15:37:45

标签: c# sqlite windows-phone-8

我的应用正在使用sqlite-net-wp8用于Windows Phone 8来管理本地数据库。

似乎数据库文件永远不会写入IsoStore(如IsoStoreSpy所示)。 没有例外被抛出。

我尝试了以下内容:

  • 将SQLite for Windows Phone从3.7.1.16升级到3.8.0.2(这是一个非常痛苦的过程)

  • 提供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)
    
  • 将SQLiteOpenFlags显式提供给SQLite.SQLiteConnection

  • 其他随机事物

这是我的代码(我正在使用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();
}

我已经没有想法了。如果有人可以帮助我,我将非常感激。

1 个答案:

答案 0 :(得分:2)

最后,解决了!

你是对的,db.Close()是多余的(Dispose将调用Close()函数。

我的非工作代码:

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

我现在正在使用的代码:

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

移除了一个小路障,还有更多路障!