迁移数据库文件后,使其在线时无法访问:

USE master   
GO
ALTER DATABASE test SET MULTI_USER
GO
ALTER DATABASE test SET ONLINE
GO



控制台输出信息:

消息 5120,级别 16,状态 101,第 1 行
无法打开物理文件 "D:\test\test.mdf"。操作系统错误 5:"5(拒绝访问。)"。
消息 5120,级别 16,状态 101,第 1 行
无法打开物理文件 "D:\test\test_log.ldf"。操作系统错误 5:"5(拒绝访问。)"。
消息 945,级别 14,状态 2,第 1 行
由于文件不可访问,或者内存或磁盘空间不足,所以无法打开数据库 'test'。有关详细信息,请参阅 SQL Server 错误日志。
消息 5069,级别 16,状态 1,第 1 行
ALTER DATABASE 语句失败。


错误日志信息:


Setting database option MULTI_USER to ON for database test.
Starting up database 'test'.
错误: 17204,严重性: 16,状态: 1。
FCB::Open failed: Could not open file D:\test\test.mdf for file number 1. OS error: 5(拒绝访问。).
错误: 17204,严重性: 16,状态: 1。
FCB::Open failed: Could not open file D:\test\test_log.ldf for file number 2. OS error: 5(拒绝访问。).
错误: 5105,严重性: 16,状态: 1。
A file activation error occurred. The physical file name 'D:\test\test_log.ldf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
错误: 928,严重性: 20,状态: 1。
During upgrade, database raised exception 945, severity 14, state 2, address 00000000009F3BD7. Use the exception number to determine the cause.



解决方法:

在数据库所在的目录中,右键文件夹——属性——添加SqlServer服务的启动账户——勾选“完全控制”——确定退出。

SQLServer 无法打开物理文件 "path\XX.mdf"。操作系统错误 5:"5(拒绝访问。)"_系统错误