Programmatically Repair SQLite Database

冷暖自知 提交于 2019-12-02 09:42:48

问题


I have a need to try and repair a SQLite database from a .NET program if the database file gets corrupted. I have found several sites such as Fix SQLite and in the FAQ it describes that you can:

Depending how badly your database is corrupted, you may be able to recover some of the data by using the CLI to dump the schema and contents to a file and then recreate.

Does anyone know of a way to repair a SQLite database programmatically in .NET?


回答1:


You are overlooking one important word: you can 'recover some data', this is not a repair!

If there is a sitatuation where a corrupted database could be repaired perfectly without user-interaction than it would not be corrupted in the first place and such an repair would have been a standard function of SQLite




回答2:


You might consider implementing your own strategy for database recovery. You could store backups of the SQLite file and then check that it is OK using:

PRAGMA integrity_check; 

If errors are found then you can revert to a backup.



来源:https://stackoverflow.com/questions/5835070/programmatically-repair-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!