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:
|SQL Server version||Corrupt MDF file||MDF file fixed by DataNumen SQL Recovery|
|SQL Server 2005||Error2_1.mdf||Error2_1_fixed.mdf|
|SQL Server 2008 R2||Error2_2.mdf||Error2_2_fixed.mdf|
|SQL Server 2012||Error2_3.mdf||Error2_3_fixed.mdf|
|SQL Server 2014||Error2_4.mdf||Error2_4_fixed.mdf|