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

后端 未结 9 1904
你的背包
你的背包 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: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.

提交回复
热议问题