Resolving SQL Error 5172

Have you ever encounter this problem when try to attach the database in SQL 2000 ?

The typical text message is Error 5172: The header for file ‘C:\Program Files\Microsoft SQL Server\MSSQL\Data\xxx.yyy is not a valid database file header. The PageAudit property is incorrect.

The general format of this error message, obtained from MSDN is : The header for file ‘%ls’ is not a valid database file header. The %ls property is incorrect.

This is occured when certain value(s) in the header information in the boot page (page 0) of the LDF or MDF file  is incorrect. You can also said that you have the corrupted data, and usually, this corrupted data is very important to you.

You can not attach the database unless some actions are taken to manually fix the file header page.

There are many causes of this error message. In this article, I will use the sample header of page 0 below :


The value at offset 0x00 (headerVersion) should be 0x01

The value at offset 0x01 (m_type) should be between 0x01 and 0x66

The value at offset 0x04 (m_flagBits) should not be 0x02

The value at offset 0x18 (m_objId) should be 0x63 or higher

The combined value at offset 0x1E and 0x1F (m_freeData) should be 0x60 or higher
(From the above example, the value is 0x0993 which is the valid value). m_freeData is the offset where the next record will be placed.

Page size (0x2000)  – m_SlotCnt * 4 should be higher than m_freeData. If it is not, any subsequent operation will overwrite existing data and this is disaster to SQL Server, and also to you 🙂

Offset 1C-1D (m_freeCnt) should be less than 0x1FA0 (8096). That’s obvious, because m_freeCnt denotes available free bytes within page, if it is greater then SQL Server has reason to drop further execution because this will end up outside the 0x2000 boundary.

As for the value 0x1FA0 (8096) is derived from page size (8192) – total header byte size (0x60) = 96 = 8192 – 96 = 8096

Apparently, offset 1E-1F (m_freeData) should not be zero

Offset 16-17 (m_SlotCnt) should less than 0xFD0 (4048)

The value at offset 0x40 thru 0x5F should be zero

You can checks for this values and manually corrects it using your favorite hex editor and try to re-attach the database


4 Responses to “Resolving SQL Error 5172”

  1. andrew Says:

    if you would make an .exe which will automatically perform the operations I would make you a statue in the center of my city 🙂

  2. Anonymous Says:

    Unfortunately, the causes that leads to the above error is rather complex. Several cases should first be well-documented before an attempt to create an application to resolve it. The best way is to examine it manually, to get a ‘feel’ of data condition and the intended recovery strategies.

  3. Riccardo Says:

    How could the combined value at offset 0x1E and 0x1F in your example be 0×0993? Could you explain it to me? Thanks

  4. ekasiswanto Says:

    thanks for your correction, it should be the same as the picture, maybe I confused it with other page sample 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: