Table of Content
    SQL Database Repair

    How to Fix SQL Database Error 5172 – The Header of File Is Not a Valid Database File Header


    Table of Content

      Summary: This blog discusses about SQL database error 5172 that indicates that the database file header is corrupt. It also provides an insight on causes and solutions of SQL Database file header corruption in MS SQL database. The solutions comprise manual methods and using a SQL recovery tool to recover the database.

      The two biggest drawbacks of a Database Management System are that it is complex and lengthy, thus making the database prone to corruption. Microsoft SQL is undoubtedly the most preferred choice amongst Relational Database Management System Administrators but this factor does not help in overcoming its drawback. Like other RDBMS, SQL Database is also hit with corruption and one of these is SQL database file header corruption.

      Stellar

      SQL server refuses to start. The ERRORLOG shows the following error about the Page Audit property:

      2017-10-30 15:45:36.36 spid9s Starting up database ‘model’.
      2017-10-30 15:45:36.37 spid9s Error: 5172, Severity: 16, State: 15.
      2017-10-30 15:45:36.37 spid9s The header for file ‘C:\Program Files\Microsoft SQL Server\MSSQL12.DAR_P11D\MSSQL\DATA\model.mdf’ is not a valid database file header. The PageAudit property is incorrect.
      2017-10-30 15:45:36.39 spid9s Error: 945, Severity: 14, State: 2.
      2017-10-30 15:45:36.39 spid9s Database ‘model’ cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server error log for details.
      2017-10-30 15:45:36.39 spid9s SQL Trace was stopped due to server shutdown. Trace ID = ‘1’. This is an informational message only; no user action is required.

      This is a case of Microsoft SQL server error 5172. You can encounter similar other errors. Before discussing about solutions to fix the error, let’s first understand the basics of the Database file Header page, its effects, possible causes, and appropriate solutions.

      What is Database File Header Page

      In SQL Server, data is stored in a unit called Page, numbered sequentially starting with 0 for the first page in the file. The first page is also known as file header page that contains information about the attributes of the file. Each file is identified with a unique File ID number. For SQL Database, Page no. and File no. together determine a page.

      Similarly, SQL data file is stored with extension .MDF and .NDF and the disk space logically distributes itself into pages numbering 0 till n. All disk Input-Output related operations are done on pages. In a nutshell, SQL server reads and writes whole data-pages. Find below structure of SQL server data file:

      Page NoPage Identify
      Page 0Header
      Page 1First PFS
      Page 2First GAM
      Page 3First SGAM
      Page 4Unused
      Page 5Unused
      Page 6First DCM
      Page 7First BCM

      Page Description – Page 0 (Header): First page of the SQL data file and occupies approx 8KB storage space. Stores metadata about that particular SQL Data file. All files have Header as Page 0, which can’t be recovered by CHECKDB. The entire file is restored if there is Damage or corruption in File Header. Check Header contents with DBCC page. A better option is “DBCC FILEHEADER” also known as purpose command.

      DBCC FILEHEADER

      When an Administrator executes SQL Database DBCC FILEHEADER command on a particular database, it searches for two parameters  – 1) Database name/ID and 2) File ID. The basic Syntax command is:

      DBCC FILEHEADER (‘DBName’, ‘FileId’);
      GO

      DBCC FILEHEADER command returns a tabular output with table contents indicating information about the database including Output, Growth, Binding ID, Status, Sector size and more.

      Output of DBCC FILEHAEDER

      Now that you have an understanding of SQL Database basics, let’s discuss SQL DB File Header Corruption error.

      Probable Reasons and Effects – SQL File Header Corruption

      As discussed above, the SQL File Header page is an important component and any corruption on this page directly affects the database to the extent that it is rendered dysfunctional. The outcome is “Inconsistency in Database” or “Complete Inaccessibility of Database” in extreme cases. It is a fact that all SQL Administrators keep a Hawk’s eye view of their database administration and remain alert 24×7; despite that unexpected reasons may lead to File Header page corruption:

      • Drivers and Controllers behaving badly
      • Unpredicted Power Outages
      • Abrupt Rebooting of SQL server

      Corporates have a backup disaster recovery plan in place but most of the time, it is either unreachable or the Administrator is not available to execute the plan.

      Solutions to Recover from Disaster

      The best way to recover is backup data restoration and almost all Corporates have a backup of their data, however, in the situation where the backup is also taken at the same location and there is a sudden power outage, and the result might be SQL backup file corruption. In that case, you need to follow the below-mentioned steps:

      1. Stop SQL Server instance
      2. Copy MDF and LDF files to another location
      3. Delete original MDF and LDF files
      4. Start SQL Server instance again
      5. Create a new database (DB) with the same DB name and Filenames
      6. Stop SQL Server
      7. Overwrite newly created MDF and LDF

      Above mentioned steps will lead to database recovery online. Establish an EMERGENCY or SINGLE USER mode for this database and execute DBCC CHECKDB as follows:

      DBCC CHECKDB (databaseName, REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS

      Note: Executing DBCC CHECKDB command may have an opposite effect – you might end-up losing partial data with flags such as REPAIR_ALLOW_DATA_LOSS. Organization’s data is crucial and it should be available as is. A partial data loss may result in business loss.

      With this option, you have ruled out a data recovery option using the manual method. The only and in fact the best way is to use Stellar Repair for MS SQL. This SQL database recovery tool repairs corrupt MDF files and restore complete data.

      free download

      Check the working process of  Stellar SQL Recovery Software:

      Conclusion

      Though RDBMS is used by most SQL Database Administrators, it is prone to corruption and unexpected shutdowns. To overcome this problem, create a backup of the precious database at a different location for easy restoration. If this option is also not available, resort to Plan B and get third-party software to deal with SQL Database File Header corruption and recover your corrupted database in no time. Corporations should have ready third-party software as an alternate backup plan to reduce business loss for want of database availability.

      Was this article helpful?

      No NO

      About The Author

      Priyanka Chauhan linkdin

      Priyanka is a technology expert working for key technology domains that revolve around Data Recovery and related software's. She got expertise on related subjects like SQL Database, Access Database, QuickBooks, and Microsoft Excel. Loves to write on different technology and data recovery subjects on regular basis. Technology freak who always found exploring neo-tech subjects, when not writing, research is something that keeps her going in life.

      9 comments

      1. While solving SQL header corruption error, I’m facing issues in SQL Agent. I looked into SQLAgent.out file and facing this error:
        “SQLServerAgent cannot start because the msdb database is not available for normal access”
        When I connected to SQL Server, MSDB database was in suspect state.

        How can I fix this error?

        1. You can fix this error, by restoring the data from the backup file.
          If you do not have the backup of the database then opt for a third party tool SQL database recovery tool like Stellar Repair for MS SQL. It is a safe and reliable way to repair corrupt database file.

      2. I have tried to reattach a database on SQL Server 2014. I got an error message:
        Error code: 5172
        The header for file ‘databaselog.ldf’ is not a valid database file header. The PageAudit property is incorrect.
        Device activation error: The physicalfile name ‘databaselog.ldf’ may be incorrect. New log file was created.
        I forgot to take the backup of database. Now how can I fix this error?

      3. We did everything to eliminate this error using manual methods. But, we still stuck in a dark zone without any possibility of recovery.

        Please help our team for instant relief!

      4. Tried these manual methods on my database but I believe my .mdf file is severely corrupted.

        Are you sure Stellar Repair for MS SQL will be able to resolve my database’s corrupted header files issue?

      Leave a comment

      Your email address will not be published. Required fields are marked *

      Image Captcha
      Refresh Image Captcha

      Enter Captcha Here :

      Related Posts

      WHY STELLAR® IS GLOBAL LEADER

      Why Choose Stellar?

      • 0M+

        Customers

      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+

        Countries

      • 0+

        PARTNERS

      • 0+

        Awards Received