尝试使用以下命令附加数据库(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
服务帐户是本地管理员组中的域帐户。我还有希望吗?
如果您可以连接(或具有管理员权限的帐户),则重复
Win Auth.
- 。Admin
attach db
问题可以通过其他用户配置来解决 - 权限改变也可以。
我注意到你帖子里有一些东西
创建数据库命令中的第一个路径是:
E:\DBA\数据\CMYDB_数据.mdf
但是在错误日志中您显示此路径不同:
E:\DBA\数据\ WFCPROD \WFCPROD_数据.mdf
您是否指定了正确的路径,帐户服务是否有权访问 E:\DBA\Data 下的 WFCPROD 文件夹?请检查