Wednesday, April 28, 2010

Resolving Error 5171 in SQL Database

SQL Server database corruption can occur due to SQL Server malfunctioning, improper system shutdown, virus infection, hardware failure and many more. Once SQL database gets corrupted, SQL server database become inaccessible. In such situations, use your backup, if there is no backup, the user needs to sql recovery software to repair mdf file. Consider a practical scenario, where a user is working on SQL Server 2005 and creating a report. While doing so, the Windows restarts due to power failure. When users restart the system, the SQL database becomes inaccessible. When the user tries to attach the MDF manually, he encounters the below error message:

“An exception occurred while executing a Transact-SQL statement or batch. _db.mdf is not a primary database file. (Microsoft SQL Server, Error: 5171).” Or

“C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\MYDATABASE.mdf is not a primary database file. (Microsoft SQL Server, Error: 5171)” In such circumstances, the database administrators recommend to attach a single file. However, when the user uses sp_attach_single_db Stored Procedures, the user encounters the following error message:

“Server: Msg 5172, Level 16, State 15, Line 1 The header for file path……\.mdf is not a valid database file header. The PageAudit property is incorrect.”

The above issue occurs when the MDF file header gets corrupted or some invalid information is inserted in the header file. All these situations result, inaccessibility of the SQL database. To ensure accessibility of the SQL database, the user needs to recover mdf by using the latest backup. But sometime user has not created any backup of its database or mdf file, then he needs to perform MDF repair. To do so, user needs to use efficient and effective SQL MDF repair application.