I have attempted to reconstruct from notes the following as my attempted recovery sequence but cannot guarantee the order of commands in detail.

I was actively using Calibre when the laptop crashed. I suspect something caused a hard disk problem which caused Windows to reboot. I do not know if it was caused by Windows, Calibre or the laptop hardware as the laptop boot complained it could not find the Operating System but Windows correctly started after a power-off and power-on.

I then used the standard Windows Check Disk on reboot to both: Automatically fix file system errors, and; Scan for and attempt recovery of bad sectors.

Then I tried to run Calibre but I got a calibre.exe is not responding error.

Traceback (most recent call last):
File "site-packages\calibre\library\restore.py", line 116, in run
File "site-packages\calibre\library\restore.py", line 279, in replace_db
WindowsError: [Error 32] The process cannot access the file because it is being used by another process

I thought that the calibre installation might be corrupt so I used the file calibre-0.9.2.msi to perform a repair.

At some point calibre asked me the following:

Choose a location for your new calibre e-book library

In doubt of the correct answer, I cancelled out and it has never been asked again so I am not sure which piece of software was asking it as I have performed the calibre installation repair more than once.

Then I tried the following command:
calibredb restore_database --really-do-it

Restoring database succeeded
old database saved as C:\Users\Steve\Calibre Library\metadata_pre_restore.db
Some errors occurred.
A detailed report was saved to calibre_db_restore_report.txt

This showed three different categories of minor problem:

One instance of:
File "site-packages\calibre\library\restore.py", line 159, in scan_library
File "site-packages\calibre\library\restore.py", line 181, in process_dir
File "site-packages\calibre\ebooks\metadata\opf2.py", line 564, in __init__
File "xpath.pxi", line 455, in lxml.etree.XPath.__call__ (src/lxml/lxml.etree.c:115107)
File "apihelpers.pxi", line 37, in lxml.etree._documentOrRaise

Two instances of:
File "site-packages\calibre\library\restore.py", line 245, in restore_books
File "site-packages\calibre\library\restore.py", line 268, in restore_book
File "site-packages\calibre\library\sqlite.py", line 313, in run
IntegrityError: columns book, format are not unique

Eleven instances of:
File "site-packages\calibre\library\restore.py", line 245, in restore_books
File "site-packages\calibre\library\restore.py", line 259, in restore_book
File "site-packages\calibre\library\database2.py", line 3352, in create_book_entry
File "site-packages\calibre\library\sqlite.py", line 313, in run
IntegrityError: PRIMARY KEY must be unique

Not bad for a database that before the crash contained more than ten thousand books and nothing to indicate any other problems. However, calibre still will not start so I tried another database repair command:

The metadata.db and metadata_pre_restore.db are both the same size (20,660 KB), but if I examine them with SQLite Database Browser 2.0 b1.exe metadata_pre_restore.db shows content (although it only contains about 4000 books) but metadata.db appears to be empty.

However, I can copy metadata.db using Windows Explorer so I do not understand the error or what I can do next.

Is it an sqlite error and what does it mean?

The permissions appear to be identical for both metadata .db files, so I cannot think of any more fixes to try without more knowledge of the errors and expected recovery behaviour. Thanks, and I apologize for the length of this account of a so-far unsuccessful recovery.

Start Calibre
-------------
Corrupted database - popup window
?
The library database at C:\Users\Steve\calibre Library appears to be corrupted.
Do you want calibre to try and rebuild it automatically?
The rebuild may not be completely successful.
If you say No, a new empty calibre library will be created.

Show details
------------
calibre, version 0.9.2
Corrupted database: The library database at C:\Users\Steve\Calibre Library appears to be

corrupted. Do you want calibre to try and rebuild it automatically? The rebuild may not be

completely successful. If you say No, a new empty calibre library will be created.

SOLUTION
--------
For a successful database rebuild, deleting the metadata.db was essential before doing the database rebuild. The following failed to delete or rename this file, so was destined to be unsuccessful with whatever was the cause of this problem. However, I have not determined whether the two ways of rebuild the database are exactly equivalent (although I assume they are).

calibredb restore_database --really-do-it

In addition, it appears the the term restore_database is misleading because it is really a rebuild_database operation as it does not recover the database from a single archive file.

Sorry, but your post is a horror for reading. A better way is to use Spoiler for your log listings. Then it is better to see what is a log and what is something what you wrote as comment or question.

If Calibre is not able to override the metadata.db then your OS is blocking the file. These mainly happen when an application is crashing without unlock the file. In this case you need to shut down the user profile and restart again. Then you can rename or delete the metadata.db and start Calibre again and rebuild the database.

Thanks for the Spoiler link but it looks like there is a serious learning curve to improve the log with the tags. What I really need is some form of utility to capture the data as I encounter the bug.

I think that my problems were caused by Calibre running in the System Tray which means that closing Calibre and restarting it was not sufficient. I have learned the lesson to log out and log back in to clear all running applications. However, it is good to know that I do not have to scrabble around for a lock file like I have to do with VMware and other virtualisation software.

Thanks for the Spoiler link but it looks like there is a serious learning curve to improve the log with the tags. What I really need is some form of utility to capture the data as I encounter the bug.

I think that my problems were caused by Calibre running in the System Tray which means that closing Calibre and restarting it was not sufficient. I have learned the lesson to log out and log back in to clear all running applications. However, it is good to know that I do not have to scrabble around for a lock file like I have to do with VMware and other virtualisation software.

When running with the system Tray ON: You can Quit by right-clicking on the tray Icon and making the selection there