Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 949
Corey Blair Avatar asked Oct 29 '12 17:10

Corey Blair


People also ask

How do I copy a SQL Server database from one instance to another?

Right-click on the database and select Tasks and then Copy Database. Once you click on Copy Database then the following screen will appear. Click on "Next". Enter the Source server name (for example, Server A) and enter the Server Authentication mode and click on "Next".

Does LocalDB require SQL Server?

It requires no configuration to run and allows for quick access to a database engine without the overhead of managing and installing a full SQL Server instance. LocalDB utilizes the minimal amount of files needed to achieve all of this.


1 Answers

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.

like image 134
BernardV Avatar answered Nov 20 '22 19:11

BernardV