简体   繁体   English

SQL Server还原错误:文件“db.mdf”的目录查找失败

[英]SQL Server Restore Error: Directory lookup for the file “db.mdf” failed

When trying to restore a dbname.bak file (from a windows machine) for SQL Server on a linux machine using: 尝试使用dbname.bak命令在Linux计算机上为SQL Server还原dbname.bak文件(从Windows计算机)时:

RESTORE DATABASE dbname
FROM DISK = '/path/to/dbname.bak'

I got the following error: 我收到以下错误:

Error: Directory lookup for the file "C:\\Program Files\\Microsoft SQL Server\\MSSQL\\DATA\\dbname.mdf" failed with the operating system error 2(The system cannot find the file specified.). 错误:文件“C:\\ Program Files \\ Microsoft SQL Server \\ MSSQL \\ DATA \\ dbname.mdf”的目录查找失败,并显示操作系统错误2(系统找不到指定的文件。)。
SQLState: S0001 SQLState:S0001
ErrorCode: 5133 ErrorCode:5133

and also another error for the dbname_log.ldf file. 以及dbname_log.ldf文件的另一个错误。

Why is SQL Server trying to reference windows files on a linux machine, I hear you ask? 为什么SQL Server试图在linux机器上引用windows文件,我听说你问?

Explanation 说明

MS SQL Server assumes by default that the file path(s) saved inside the dbname.bak is where the database should be restored to. 默认情况下,MS SQL Server假定dbname.bak保存的文件路径是数据库应还原到的位置。 If the file path(s) don't exist, you'll get an error like that. 如果文件路径不存在,您将收到类似的错误。

Solution

Explicitly tell the DB to use a different file(s). 明确告诉DB使用不同的文件。 But first you need to know how the file(s) is (are) referred to by executing the following T-SQL: 但首先,您需要通过执行以下T-SQL来了解文件是如何被引用的:

RESTORE FILELISTONLY FROM DISK = '/path/to/dbname.bak'

which might give you something like this: 这可能会给你这样的东西:

Dbname_Empty
Dbname_Empty_log

which you can then use to execute the following T-SQL: 然后,您可以使用它来执行以下T-SQL:

RESTORE DATABASE dbname
FROM DISK = '/path/to/dbname.bak'
WITH MOVE 'Dbname_Empty' TO '/var/opt/mssql/data/dbname.mdf',
MOVE 'Dbname_Empty_log' TO '/var/opt/mssql/data/dbname.ldf'

hopefully without getting any errors. 希望没有任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置用于备份和还原SQL Server数据库的指令(更改.mdf和.log文件) - Instructions set for backup and restore of SQL Server's DB (changing .mdf and .log file) SQL Server 错误 5120 - 附加 .mdf 文件失败 - SQL Server Error 5120 - failed to attach .mdf file SqlException:无法打开登录请求的数据库“ path \\ db.mdf”。 登录失败。 用户“ NT AUTHORITY \\ SYSTEM”的登录失败 - SqlException: Cannot open database “path\db.mdf” requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM' 从SQL Server 2008 MDF文件还原记录的最快方法 - Quickest way to restore a record from a SQL Server 2008 MDF file 将数据库(.mdf文件)附加到SQL Server时出错 - Error attaching a database (.mdf file) to SQL Server SQL Server MDF文件 - SQL Server MDF file 无法在SQL Server中以.mdf扩展名还原数据库 - Cannot restore database with .mdf extension in sql server 如何使用T-SQL或.net代码将Mdf / ldf数据库文件转换为.bak文件(db restore) - how to convert Mdf/ldf database files to .bak file (db restore) using T-SQL or .net code SQL Server 2008 Express无法附加mdf文件 - SQL Server 2008 Express failed to attach mdf file SQL Server 还原错误 - 写入??? 失败的 - SQL Server Restore Error - Write on ??? failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM