拿C#写UWP访问数据库的时候出现了问题,attempt to write a readonly database
,一般是由于访问权限的的限制,最简单的办法就是把要用的数据库复制到LocalFolder
里面
这屑问题折腾了我一下午(
//复制文件,执行一次就够了,用完即删
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("your-file-path"));
await file.CopyAsync(localFolder, "any name", NameCollisionOption.FailIfExists);
//用这个方式打开数据库
string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "abc.db");
SQLiteConnection connection = new SQLiteConnection($"Data Source={dbpath}")