I am planning to use localdb
for next project and thinking of making rotating backup of database (it will be detached normally and only attached when software is running). And I was thinking how to do automatic restore from backup. This required me to know if database is corrupted. And I can't find anything about this subject.
My guess, peoples don't care on that level about database integrity. Backup and maintenance is a job for IT, there are dozens of tools for SQL Express.
My database will be local on PC and not big. I want to make it very simple:
- detect if database is corrupt (how?)
- offer user an option to restore database from most recent backup (this is easy)
P.S.: perhaps I don't know something about sql express, localdb, linq-to-sql. This is why question is very generic.
After getting answer I'll go with simple options:
- if database can't be opened and file exists - database is corrupted, offer restore (not exists - create empty database and do initial setup);
- provide following options (if user noticed something unusual or get errors during update, etc.): to check database
DBCC CHECKDB (0, REPAIR_REBUILD)
(could be good to try first) or to restore.
Automatic detection seems costly. Rather keep weekly/montly backup for manual restoration (if that would be really necessary for old data) and create mdf-file backup every run to minimize loss to 1 day maximum (which in my case is totally fine for an abnormal situation like database corruption).