0

我正在尝试关注以下文章: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);

知道为什么这种情况继续发生吗?

4

1 回答 1

0

我不确定,它将如何工作c#。通常,sqlite如果您打开数据库,则在您的操作完成后您应该打开close它。

以防万一,如果您忘记了close您的sqlite database,它会保持忙碌。

于 2013-01-29T11:27:14.023 回答