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:

Precise Explanation:

The data in an MDF file are stored as pages, with each page being 8KB in size. The first page, called the file header page, contains the most important information about the entire file, including the file signature, size, compatibility, and other essential details.

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 Files:

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