microsoft sql server error 5120 access denied

14 Nov

Use the below script to find the sql service account


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)

After getting the service account try the below steps to provide privilege


  • Right click on the folder where your database file like (Testdb.mdf & Test.ldf) and click on properties
  • Click on security tab
  • Click on Add button and add sql service account
  • Provide modify privilege and click ok
  • Verify both mdf and ldf have modify privilege
  • Give full control againt your system login user
  • Attach the db!
Leave a comment

Posted by on November 14, 2013 in SQL Query


Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: