How do I copy SQL Server 2012 database to localdb instance?

后端 未结 9 1883
你的背包
你的背包 2021-02-04 00:49

I\'m looking to copy a SQL Server 2012 Standard database to my localdb instance. I\'ve tried the wizard which complains that localdb isn\'t a SQL Server 2005 or later expres

相关标签:
9条回答
  • 2021-02-04 01:01

    I had the same problem. What eventually did work was this:

    1. Trying to restore the database (getting the error in the OP)
    2. Detaching the database
    3. Reattaching the database

    What happened in the last step was that SSDT performed an upgrade of the data files, that apparently was in an older format. When that was finished, the database started working without any problem!

    0 讨论(0)
  • 2021-02-04 01:02
    RESTORE FILELISTONLY
    FROM DISK = 'D:\SQLBackups\yourdatabase.BAK'
    
    
    ALTER DATABASE yourdatabasename
    SET SINGLE_USER WITH
    ROLLBACK IMMEDIATE
    
    RESTORE DATABASE yourdatabasename
    FROM DISK = 'D:\SQLBackups\yourdatabase.BAK'
    with replace,
    move 'logical name from file stream' to
    'C:\yourdatabase.mdf',
    move 'logical name from file stream' to 'C:\Yourdatabase.ldf'
    ALTER DATABASE Qatar_DB SET MULTI_USER
    
    0 讨论(0)
  • 2021-02-04 01:02

    I had the same problem. Try running visual studio as Administrator and try the following command

    RESTORE DATABASE CSODev
    FROM DISK = 'C:\MyBckDir\CSODev.bak'
    WITH NORECOVERY, MOVE 'CSOdev_Data' TO 'C:\Users\cblair\CSOdev_Data.mdf',
    MOVE 'CSOdev_Log' TO 'C:\Users\cblair\CSOdev_Log.ldf',
    

    UPDATE: This did not work exactly!

    Although the above statement does not produce any errors and completes successfully, the database remains in "PENDING RECOVERY" state and cannot be accessed in any way. When I tried to 'RESTORE WITH RECOVER' to bring the database online I got the same error as in the question above.

    So in my case I ended up restoring the backup to a DEV server I have running with MSSQL 2008 R2 and then chose: Tasks -> Generate Scripts -> chose objects to script & Next -> click on "Advanced" button -> select "types of data to script" : Schema & data. Now run the generated script against the local db.

    0 讨论(0)
  • 2021-02-04 01:08

    Same problem, thanks for the help. My local database is MS SQL 2014. Open "SQL Server 2014 Management Studio"

    1. Right click the database, go to "Tasks", click "Take Offline"
    2. Detach the database
    3. Attach the database

    It work for me. After you backup the database, you can restore the database without error. Thanks.

    0 讨论(0)
  • 2021-02-04 01:13

    There is known limitation (a real bug, in fact) for localDB. It will fail any RESTORE with MOVE whenever your database files are located in different folders.

    You have to restore in the original folders (no MOVE). Use cmd tool such as SUBST if you need to fake a drive:/path.

    0 讨论(0)
  • 2021-02-04 01:14
    1. You can do it manually. this can be done by using dot net and opening two kinds of connections and forwarding data from one of them to the other. but this needs to create the same types of columns in the local one.
    2. You can check the importing options of MS Access 2007
    0 讨论(0)
提交回复
热议问题