restoring database in sql server 2012

  • Hi All,

    Someone gave me a .bak copy of the database. I tried to attach that database to my server and it keeps giving me an error saying "Db1.bak" is not a primary database file. I tried to change the extension of the database file to .mdf and then it gave me the same error saying C:\Databases\db1.mdf is not a primary database file(Microsoft sql server Error 5171).

    I also tried to right click on the database and selected Restore database. I selected "Device" and pointed to my backup file and then I choose the Database name, but the OK button the bottom of the Restore database dialog does not get highlighted. I don't know how to do this sql server 2012.

    Any help will be greatly appreciated.

  • ATTACH is for an db1.MDF/db1.LDF pair of files.

    what you need to do is RESTORE the database from a file.

    http://www.mytechmantra.com/LearnSQLServer/How-to-Restore-Database-SQL-Server-P1.html

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • This was removed by the editor as SPAM

  • JasonClark (1/3/2017)


    There are many symptoms which points in the direction of the error 5171.

    However in this case it's because he tried to attach a backup instead of restoring it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • anjaliagarwal5 (1/3/2017)

    I also tried to right click on the database and selected Restore database. I selected "Device" and pointed to my backup file and then I choose the Database name, but the OK button the bottom of the Restore database dialog does not get highlighted.

    Have you filled in any necessary fields on the other tabs, Files and Options?

  • All respect to the GUI, it's so much easier to backup and restore databases using T-SQL. Here's a good intro on the topic [/url]that ought to give you everything you need.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Try T-SQL instead of GUI for restoring database.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply