When trying to attach a .MDF database in SQL Server, you see the following error message:
Attach database failed for Server 'xxx'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
The header for file 'xxx.mdf' is not a valid database file header. The FILE SIZE property is incorrect.（Micosoft SQL Server, Error:5172）
where 'xxx.mdf' is name of the MDF file to be attached.
Screenshot of error message:
The data in MDF file are stored as pages, each page is 8KB. The first page is called the file header page, which contains the most important information about the whole file, such as the file signature, file size, compatibility, etc.
If the MDF file header page is damaged or corrupted, and cannot be recognized by Microsoft SQL Server, then SQL Server will think the header is not valid and report this error.
You can use our product DataNumen SQL Recovery to recover the data from the corrupt MDF file and solve this error.
Sample corrupt MDF files that will cause the error: