SQL Database is corrupted

5 pts.
SQL Database
SQL Server 2005
Respected sir, Unfortunately the hard disk of my system is damaged, now I recovered my database. but it cannot be attached again to SQL management studio 2005. The error is myfile.mdf is not a primary database file. (SQL server, error 5171) Please sir help me.

Answer Wiki

Thanks. We'll let you know when a new response is added.

in SQL server database can happen due to any uncertain like virus attack, power
failure, hardware issue, OS malfunction, sudden system shutdown, so on. When a
SQL server data file (.mdf) is corrupt then DBAs can try several methods to
repair and recover data from it. 

  • Run DBCC CHECKDB: It checks & reports all the error message in
    errorlog, if there is any problem with the database. Try to analyze &
    understand the error message logged in the errorlog. Re-run DBCC CHECKDB
    with the recommended minimum repair option to repair the file. 

Detailed information about DBCC CHECKDB is available

  • Restore from backup: If above command fails to fix the error
    message the try to restore the database from clean backup. 
  • 3rd party tool: Try 3rd party Recovery Toolbox for SQL Server to
    recover data from corrupt mdf file. Most of the software have demo version
    that shows the preview of corrupt SQL server data file. 


Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • markwillium
    As a resolution to the SQL server error message 5171, you can use 'sp_attach_db' for attaching the database. 

    Note: sp_attach_db won't work, if you do not use 'sp_detach_db' for detaching the same database. 

    Another possible remedy is to use 'CREATE DATABASE' command with the 'FOR ATTACH' clause.
    30 pointsBadges:
  • clark445kent

    I have googled about your query and I have got a article http://www.sqlrecoverysoftware.net/blog/how-to-fix-sql-error-5171.html for it. I hope this is help full for you. 
    8,235 pointsBadges:
  • johnwalker10
    you can also take the help of this video tutorial that shows how to fix SQL Server Error 5171: https://www.youtube.com/watch?v=yt_DeOOErmk 
    60 pointsBadges:
  • TheRealRaven
    "...now I recovered my database."

    There isn't enough info for us to guess how to help. We need to what steps you took to repair your "damaged" hard drive, and especially the detailed steps you try to "recover" your database.

    It might be easy to recover if you have a good backup, or it might be difficult (or costly) if you took your database from a damaged hard drive.

    But we need to know the actual steps you took and the things you have available to work with such as backup copies.

    Also, we need to know what action you were taking when the error message was thrown and the exact text of the error.
    37,065 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: