EXEC sp_attach_db @dbname = 'store',
@filename1 = 'D:\XX.mdf',
@filename2 = 'D:\XX_log.ldf'
Press F5 or run button to execute.
Console output: appears
Unable to open physical file “D:\XX. MDF “. Operating system error 5:”5(access denied). ”
error log information:
Setting database option MULTI_USER to ON for database store.
Starting up database ‘store’.
error: 17204, severity: 16, status: 1.
FCB::Open failed: Could not Open file D:\store\store. MDF for file number 1. OS error: 5(denied access)
error: 17204, severity: 16, status: 1.
FCB::Open failed: Could not Open file D:\store\store_log.ldf for file number 2. OS error: 5(denied access)
error: 5105, severity: 16, status: 1.
A file activation error occurred. The physical file name’d :\store _store_log.ldf may be pen. account and correct additional errors, and retry The operation.
error: 928, severity: 20, status: 1
During upgrade, database raised exception 945, database raised exception 14, state 2, address 00000000009F3BD7. Use the exception number to determine the cause.
Solutions:
In the directory where the database resides, the folder where the MDF and LDF files are stored, right-click the folder — properties — security — Add the SqlServer service startup account or Everyone — check the box “Complete Control” — to exit.
Finally, rerun the above code.