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

localdb, sql, sql-server, sql-server-2012

Solution

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.

Problem

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 express instance. I also did a backup/restore but upon the restore in my localdb I get the following error... Running this... ``` RESTORE DATABASE CSODev FROM DISK = 'C:\MyBckDir\CSODev.bak' WITH MOVE 'CSOdev_Data' TO 'C:\Users\cblair\CSOdev_Data.mdf', MOVE 'CSOdev_Log' TO 'C:\Users\cblair\CSOdev_Log.ldf', REPLACE ``` Error message I get... Processed 8752 pages for database 'CSODev', file 'CSOdev_Data' on file 1. Processed 5 pages for database 'CSODev', file 'CSOdev_Log' on file 1. Msg 1853, Level 16, State 1, Line 1 The logical database file 'CSOdev_Log' cannot be found. Specify the full path for the file. Msg 3167, Level 16, State 1, Line 1 RESTORE could not start database 'CSODev'. Msg 3013, Level 16, State 1, Line 1 RESTORE DATABASE is terminating abnormally. The database ends up in "Recovery Pending" mode. It seems like it has issues with the log file. I have tried 2 different backups in case one was just corrupted.

Original source