Problem:
Sometimes, In SQL Server database when a user trying to attach a .mdf file to a named instance of SQL Server using the SQL UI Management Studio or the below T-SQL script:
CREATE DATABASE Testdatabase ON (FILENAME = 'C:\Testdatabase_Data.mdf') FOR ATTACH_REBUILD_LOG;
It displays the Microsoft SQL Server error 5172 which says the .mdf is not a valid database file header. The FILE SIZE property is incorrect.
In this article we will know: -
Solution:
The SQL Server stores its physical data in primary database file, which contains the data according to pages. The header information of a .mdf file is hold by first page, which is known as the header page. This page contains the important information of that database file like: file size and signature etc.While attaching the .mdf file in SQL Server, One of the most common error users encounter i:e Microsoft SQL Server Error 5172. The issue .mdf is not a valid database file header generally occurs when the header information of a .mdf file gets corrupted. Due to this the header file information got mismatched and the result of this error could be the database becomes inaccessible.
There could be several reasons behind of header information corruption. It could be corrupt due to following reasons:
These corruption reasons could be result the issue file size property is incorrect SQL Server and make the database file inaccessible or user failed to attach the database file and get this SQL Server error 5172.
In order to fix this error, one can try restoring the recent backup of the database. If you have a latest copy of backup then it is the right time to use it. Sometimes, the Microsoft SQL Error 5172 arises when a higher version database file is attached to a lower version Server. So, make sure that the database file is attached with the right version to prevent such situation.
Another method to solve this database file header issue is to try SQL Database Recovery Software, if you don't have the recent backup. The software is capable to fix the file size property of a database file and resolve the issue "mdf is not a valid database file header".
Follow the Below Steps to Resolve SQL Server Error 5172:
There could be several reasons behind the header information corruption. The article describes some major issues which could be the cause of SQL Server error 5172. Also, it explains the possible recovery solution to fix the issue .mdf is not a valid database file header.