locked
SQL Server 2012 attaching file error RRS feed

  • Question

  • hello,

    i have sql server management studio 2012

    when im attaching an mdf file to database i get an error:

    cannot attach a database with the same name as an existing database. (Microsoft.SqlServer.Smo)

    i tried to search in forums, but with no access.

    thanks for helpers 

    Wednesday, March 5, 2014 6:16 AM

Answers

  • use query like this

    CREATE DATABASE <New database name> ON (FILENAME = N'your mdf file path') , (FILENAME = N'your ldf file path') FOR ATTACH;

    if you dont have ldf file just use this instead

    CREATE DATABASE <New database name> ON (FILENAME = N'your mdf file path') FOR ATTACH_REBUILD_LOG



    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Shanky_621MVP Wednesday, March 5, 2014 9:00 AM
    • Marked as answer by tracycai Wednesday, March 12, 2014 11:10 AM
    Wednesday, March 5, 2014 8:52 AM

All replies

  • just attach it with different name as it seems same database exists already on the instance

    you need to use Attcah As option specified here

    http://technet.microsoft.com/en-us/library/ms190209.aspx


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    Wednesday, March 5, 2014 6:24 AM
  • i changed the name of the mdf file and i got same error message .
    Wednesday, March 5, 2014 8:16 AM
  • Not name of the file

    you need to use Attach as option and change name of the  destination database to which it gets attached


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    Wednesday, March 5, 2014 8:47 AM
  • use query like this

    CREATE DATABASE <New database name> ON (FILENAME = N'your mdf file path') , (FILENAME = N'your ldf file path') FOR ATTACH;

    if you dont have ldf file just use this instead

    CREATE DATABASE <New database name> ON (FILENAME = N'your mdf file path') FOR ATTACH_REBUILD_LOG



    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Shanky_621MVP Wednesday, March 5, 2014 9:00 AM
    • Marked as answer by tracycai Wednesday, March 12, 2014 11:10 AM
    Wednesday, March 5, 2014 8:52 AM
  • i will try thanks
    Wednesday, March 5, 2014 9:05 AM