一.问题分析
此问题的提示也就是数据库文件损坏。如果在程序访问数据库期间拷贝是很容易出现该问题的,断开所有连接去拷贝在实际项目中有时候是不现实的,所以我们有时去做一下手动修复。
二.问题修复
1.下载sqlite3.exe到本地,并将损坏的数据库文件拷贝到同一个目录
2.打开命令行工具(CMD),进入到sqlite3.exe所在目录
3.使用sqlite3.exe打开损坏的数据库文件,并导出sql语句到临时文件
E:\sqlite>sqlite3.exe 2022_03_03.log
SQLite version 3.26.0 2018-12-01 12:34:55
Enter ".help" for usage hints.
sqlite> .output temp.sql
sqlite> .dump
sqlite> .exit
4.修改临时文件 temp.sql
将文件最后一行的 Rollback 改为Commit
5.新建数据库文件 newDB
E:\sqlite>sqlite3.exe
SQLite version 3.26.0 2018-12-01 12:34:55
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open newDb
6. 读取数据到新数据库
sqlite> .read temp.sql
sqlite> .exit
至此数据库文件就修复完成,我们就可以使用newDB来查询我们所需的数据