When trying to attach a .MDF database in SQL Server, you see the following error message:
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
xxx.mdf is not a primary database file. (Microsoft SQL Server, Error: 5171)
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. The remaining pages also contain the important information, including the page allocation information as well as the actual data.
If the MDF file header page, or other important management pages are damaged or corrupted, and cannot be recognized by Microsoft SQL Server, then SQL Server will think the whole file is not a valid primary database file 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: