【发布时间】: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/…