![net5 wpf sqlite attempt to write a readonly database的解决办法-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2020/12/2020121518012910.jpg)
.NET5 WPF 程序安装后,涉及到写入Sqlite的会报 attempt to write a readonly database 的错误。
出现这个问题首先会想到看看sqlite的数据库文件是不是设置了只读,但发现不是这样的。网上这个问题的解决方法也不多,要手动设置Users有写入的权限
,如下图所示:
![net5 wpf sqlite attempt to write a readonly database的解决办法-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2020/12/2020121517515578.jpg)
但是这种方式对用户是不友好的,因为安装完程序,还要打开安装目录,设置数据库文件的Users权限。
打包程序的时候也没有设置权限的地方,索性就使用管理员权限运行此程序。具体设置方法如下:
1.在WPF项目上右键,添加—>新建项
2.找到应用程序清单文件app.manifest
![net5 wpf sqlite attempt to write a readonly database的解决办法-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2020/12/2020121517564686.jpg)
3.修改requestedExecutionLevel 为 requireAdministrator 默认为:asInvoker
![net5 wpf sqlite attempt to write a readonly database的解决办法-程序旅途](https://www.chengxulvtu.net/wp-content/uploads/2020/12/2020121517590643.jpg)
这样程序运行就需要管理员的权限了,相应的也就有了写入sqlite的权限