While attaching the databse to the SQL server getting the below error, I want to recover my corrupted database please help me

Gaus Shaikh 0 Reputation points
2023-09-12T06:59:48.04+00:00

While attaching the databse to the SQL server getting the below error, I want to recover my corrupted database please help me :

error: TITLE: Microsoft SQL Server Management Studio ------------------------------ Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc) For help, click: https://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) ------------------------------ C:\Program Files\Microsoft SQL Server\MSSQL15.RRICMDB\MSSQL\DATA\Munim009.mdf is not a primary database file. (Microsoft SQL Server, Error: 5171) For help, click: https://docs.microsoft.com/sql/relational-databases/errors-events/mssqlserver-5171-database-engine-error ------------------------------ BUTTONS: OK

SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. RahulRandive 10,486 Reputation points Volunteer Moderator
    2023-09-12T21:37:27.14+00:00

    Hi @Gaus Shaikh

    Please locate a similar thread and any potential solutions for such errors in the following discussion-

    https://learn.microsoft.com/en-us/answers/questions/384370/sql-server-error-5171-mdf-is-not-a-primary-databas

    Thank you!

    0 comments No comments

  2. ZoeHui-MSFT 41,491 Reputation points
    2023-09-13T03:22:19.3733333+00:00

    Hi @Gaus Shaikh,

    You may also check this thread for the same issue.

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  3. Olaf Helper 47,436 Reputation points
    2023-09-13T05:36:01.3866667+00:00

    Microsoft SQL Server, Error: 5171

    select *
    from sys.messages
    where message_id = 5171 and language_id = 1033
    
    

    *=> %.ls is not a primary database file.

    As the message says, you try to attach some file which isn't a valid primary database file.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.