SQLite appeared to write to read a readonly database solution

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}")
Published 2 original articles · liked 0 · visits 23

Guess you like

Origin blog.csdn.net/qq_28086751/article/details/105495120