At some situation, when a
database administrator tries to attach the SQL server database files
(.mdf, .ndf or .ldf) to the SQL server, he might get below error
message:
Unable to open physical
file "E:\BackEnd-accounts\GlDataSQL.mdf". Operating system
error 5: "5(access is denied.)". (Microsoft SQL Server:
Error 5120)
Reason
behind above Error message:
The main reason behind above error message is that the account from
which you are trying to attach the database files does not have
enough privilege for the specific files (.mdf, .ndf or .ldf).
Troubleshoot
above Error message:
You can troubleshoot above error message by providing the privilege
to the account from which your are trying to attach the files. You
can give the permission to the account by following:
Run
below script to get service account.
Code
Snippet
declare
@sqlser varchar(20)
EXEC
master..xp_regread @rootkey='HKEY_LOCAL_MACHINE',
@key='SYSTEM\CurrentControlSet\Services\MSSQLSERVER',
@value_name='objectname',
@value=@sqlser
OUTPUT
PRINT
'Account
Starting SQL Server Service:'
+convert(varchar(30),@sqlser)
Now
you can provide privilege to the account by following steps:
- Press right button of your mouse on the folder E:\BackEnd-accounts.
- Now click on properties section and select security tab.
- Now click on Add button to add a SQL service account.
- Modify privilege setting and click OK button
- Make sure all the files have modify privilege.
- Now try to attach the database files.
- Done
For
Example:
In my case, I have given the right to the local administrator and
problem was solved. For your reference I am attaching an image
below.
Thanks the best solution i have read
ReplyDeleteit has been solve my same problem
Amr Swilam