Problem:
When trying to access a database the error occurs:
database file appears corrupt (wrong type page)
page xxxx is of wrong type (expected x, found x)
Solution:
Corruption has most likely occurred in the database. There are a few
options to try, but some data may be lost. You can take steps to
salvage the data (discussed later), but a fresh database will have
to be made. A gbak of the database is not sufficient in most cases,
because suttle corruption can be propagated through a gbak backup
and restore.
To remedy the corrupted database, one can either run gfix against the
database or copy the data to a new database. Copy data table by table,
committing each, until all data has been copied.
Steps to fix database:
--------------------------------
1) always work with a copy of the database in case further damage
occurs. Working with a copy also gives you exclusive access
which is required to perform the following operations:
2) gfix -v -f database.gdb
3) if previous step reports corruption: gfix -m -i database.gdb
4) repeat step 2 to see if the corruption was fixed
Steps to salvage data
-------------------------------
1) create a new database with the same metadata structure:
A) gbak -m will backup only the metadata. It can then
be restored to create a new database.
B) isql -x -a will extract the metadata to a script file.
isql -i scriptfile will then create the new database.
2) copy the data to the new database:
A) Delphi's datapump can be used to copy data from all tables
to a new database.
B) use isql to perform a table by table copy of the data.