SQLite出现attempt to write a readonly database解决

拿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}")
发布了2 篇原创文章 · 获赞 0 · 访问量 23

猜你喜欢

转载自blog.csdn.net/qq_28086751/article/details/105495120
今日推荐