我正在尝试关注以下文章: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);
知道为什么这种情况继续发生吗?