我正在尝试按照以下文章: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);
知道为什么会继续发生这种情况吗?
答案 0 :(得分:0)
我不确定,它如何在c#
中发挥作用。同样地,在sqlite
中如果您打开了数据库,则在完成操作后,您应该close
。
如果您忘记了close
sqlite database
,那么它会让自己忙碌。