There was a problem when using C # to write UWP to access the database attempt to write a readonly database
. Generally, due to the limitation of access rights, the easiest way is to copy the database to be used LocalFolder
.
This crumbling problem tossed me all afternoon (
//复制文件,执行一次就够了,用完即删
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}")