尝试使用以下命令附加数据库(SQL 2016):
CREATE DATABASE [MYDB]
ON (FILENAME = 'E:\DBA\Data\MYDB_Data.mdf')
FOR ATTACH;
出现以下错误:
Msg 5120, Level 16, State 101, Line 4
Unable to open the physical file "E:\DBA\Data\MYDB_Data.mdf". Operating system error 5: "5(Access is denied.)".
Msg 1802, Level 16, State 7, Line 4
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
其他人认为权限可能是问题所在。但我的情况并非如此:
PS E:\DBA\Data> icacls .
. NT SERVICE\MSSQLSERVER:(F)
BUILTIN\Administrators:(F)
CREATOR OWNER:(OI)(CI)(IO)(F)
NT AUTHORITY\SYSTEM:(OI)(CI)(F)
BUILTIN\Administrators:(OI)(CI)(F)
NT SERVICE\MSSQLSERVER:(OI)(CI)(F)
Successfully processed 1 files; Failed processing 0 files
PS E:\DBA\Data> icacls .\MYDB_Data.mdf
.\MYDB_Data.mdf BUILTIN\Administrators:(F)
NT AUTHORITY\SYSTEM:(F)
NT SERVICE\MSSQLSERVER:(F)
Successfully processed 1 files; Failed processing 0 files
服务帐户是本地管理员组中的域帐户。我还有希望吗?