【问题标题】:In Windows Phone 8, SQLite works but doesn't write the database file to IsoStore在 Windows Phone 8 中,SQLite 可以工作,但不会将数据库文件写入 IsoStore
【发布时间】:2013-09-06 15:37:45
【问题描述】:

我的应用使用sqlite-net-wp8 for 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)
    
  • 向 SQLite.SQLiteConnection 显式提供 SQLiteOpenFlags

  • 其他随机的东西

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

我的想法已经用完了。如果有人可以帮助我,我将不胜感激。

【问题讨论】:

  • 您为什么要自己Close()ing 数据库连接? using 不应该为你做那件事吗?
  • 您好我有一个疑问,无论数据库可能是什么,sql lite 或其他东西,在 windows 手机中,文件只会保存在隔离存储中,对吗?或者如果文件保存在其他地方。

标签: c# sqlite windows-phone-8


【解决方案1】:

终于解决了!

你是对的,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");

移除了一个小障碍,还有更多的路要走!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多