【问题标题】:Inserting to a sqlite database in windows 8 store app always return "Busy"在 Windows 8 商店应用程序中插入 sqlite 数据库总是返回“忙碌”
【发布时间】:2013-01-29 02:28:51
【问题描述】:

我正在尝试关注以下文章:http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/

我有以下将复制现有 sqlite 数据库的类:

public class DataHandler
    {
        public static string GetPath()
        {
            return ApplicationData.Current.LocalFolder.Path + @"\myDB";
        }

        public async void CopyDatabase()
        {
            bool isDatabaseExisting = false;

            try
            {
                StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("myDB");
                isDatabaseExisting = true;
            }
            catch
            {
                isDatabaseExisting = false;
            }

            if (!isDatabaseExisting)
            {
                StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("myDB");
                await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
            }
        }
    }

我可以使用以下代码成功查询数据库:

SQLiteAsyncConnection conn = new SQLiteAsyncConnection(DataHandler.GetPath());
            var query = conn.Table<appSetting>().Where(x => x.appSettingId == id);
            var result =  await query.ToListAsync();

            foreach (var item in result)
            {
                this.appSettingId = item.appSettingId;
                this.appVersion = item.appVersion;
            }

但是,每当我尝试使用以下代码进行插入时,我总是会收到“忙碌”的 sqliteexception

appSetting app = new appSetting{
                    appSettingId = 2,
                    appVersion = "2.0"
                };

                var conn = new SQLiteAsyncConnection(DataHandler.GetPath());
                var result = await conn.InsertAsync(app);

知道为什么这种情况不断发生吗?

【问题讨论】:

  • 该特定数据库上的授予权限设置是什么......?可以手动插入记录吗?
  • @DJKRAZE 如果我转到 ApplicationData.Current.LocalFolder.Path + @"\myDB" 并使用 SQLite 数据库浏览器打开 sqlite 数据库,我可以向其中插入数据。
  • 我认为 Tim Heuer 的出色示例已成为将 SQLite 整合到 Win 8 应用程序中的黄金标准。 timheuer.com/blog/archive/2012/08/07/…

标签: c# sqlite windows-8


【解决方案1】:

我不确定它在 c# 中的工作方式。通常情况下,sqlite如果你打开了你的数据库,你的操作完成后你应该close它。

万一你忘了close你的sqlite database,它会一直忙。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多