如何将 SQL Server 2012 数据库复制到 localdb 实例?

2022-01-03 00:00:00 sql sql-server sql-server-2012 localdb

我希望将 SQL Server 2012 Standard 数据库复制到我的 localdb 实例.我尝试过向导,它抱怨 localdb 不是 SQL Server 2005 或更高版本的快速实例.我也做了备份/恢复,但在我的 localdb 中恢复时,我收到以下错误...

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...

运行这个...

RESTORE DATABASE CSODev
FROM DISK = 'C:MyBckDirCSODev.bak'
WITH MOVE 'CSOdev_Data' TO 'C:UserscblairCSOdev_Data.mdf',
MOVE 'CSOdev_Log' TO 'C:UserscblairCSOdev_Log.ldf',
REPLACE

我收到的错误消息...

Error message I get...

已处理数据库CSODev"的 8752 页,文件 1 上的文件CSOdev_Data".
为数据库CSODev"处理了 5 页,文件 1 上的文件CSOdev_Log".

Processed 8752 pages for database 'CSODev', file 'CSOdev_Data' on file 1.
Processed 5 pages for database 'CSODev', file 'CSOdev_Log' on file 1.

消息 1853,级别 16,状态 1,第 1 行
找不到逻辑数据库文件CSOdev_Log".指定文件的完整路径.
消息 3167,级别 16,状态 1,第 1 行
RESTORE 无法启动数据库CSODev".
消息 3013,级别 16,状态 1,第 1 行
RESTORE DATABASE 异常终止.

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.

数据库最终处于恢复等待"模式.日志文件似乎有问题.我尝试了 2 个不同的备份,以防其中一个损坏.

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.

推荐答案

有已知限制(实际上是一个真正的错误).每当您的数据库文件位于不同的文件夹中时,它都会使任何带有 MOVE 的 RESTORE 失败.

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.

您必须在原始文件夹中恢复(无 MOVE).如果你需要伪造一个驱动器:/路径,请使用诸如 SUBST 之类的 cmd 工具.

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

相关文章