Sunday, July 13, 2014

[MSSQL] Access Denied attaching a database when permissions are inherited

If you attempt to attach a database, and the mdf/ldf files are in a directory where your user account has privileges only through a group, you get an access denied error. If you grant the same privilege set directly to your user account, the attach succeeds.
Error: Operating system error 5: "5(Access is denied)". (Micorsoft SQL Server, Error: 5120)
Try following steps:
  1. Delete LDF file from folder where is saved your both files,
  2. Go to the [Management Studio] and try to attach the same database,
  3. When you come in window in which you select database to attach, you will see in second list its remarked that "LDF file is not founded",
  4. You just select LDF file and click on button [Remove],
  5. Click button [OK] and your database will be attached.
This happened because something of your privileges are saved in LDF file. For that reason you must to clear this information.
If it still doesn't solve then you can do the following steps:
  1. un-checking the [Read-only] attribute from the files and folders on this path,
  2. [Start] => [Run...] => type services.msc,
  3. Scroll through the list of services until you find 'SQL Server ...' => Right-click => [Properties] => Click on [Log On] tab,
  4. Copy the content of field [This Account] (e.g.: NT Service\MSSQL$SQLEXPRESS) => [Cancel],
  5. Right-click to MDF file => [Properties] => click on [Security] tab => [Edit] => [Add...],
  6. Fill with copied value from [This Account] in services => [OK],
  7. Checking the [Allow] for 'Full Control' => [Apply] => [OK].
Last steps if the ways above could not solve the problem:
  1. Right-click to [SQL Server Management Studio] then choose [Run as admnistrator]
  2. Try to attach the database. Once it is attached then you can access the database with normal way.
  3. Quit from [SQL Server Management Studio], then access [SQL Server Management Studio] with usual authority (just click to the icon).
Source:

No comments:

Post a Comment