Server principal ‘LoginName’ has granted one or more permission(s). Revoke the permission(s) before dropping the server principal

A good DBA likes to keep his/her SQL Server environment clean and neat, that’s why dropping old, unused or unnecessary logins and users is always fun. However,  dropping a user or login can cause many unexpected troubles if you don’t carefully observe the permissions and roles and objects that could be related to that account. Unfortunately, there is no easy way to track down or analyze all server or database level permissions, users and roles related to one specific login.

I have scripts which runs every hour and checks and stores all roles and permissions to inventory tables. Before I clean up my logins, i always have a look at these tables to prevent any possible problem.

Today I was doing my routine task but i couldn’t drop one domain account and SQL Server returned this generic error :

loginfail

I am surprised because I double check my tables, there shouldn’t be a object or role or permissions bound to this account. The problem was this account was the grantor of a permission, not the grantee. I looked at my tables and I found that this account granted “CONNECT” permission on Always On Endpoint to another account.

This can also be checked with the below query:

SELECT * FROM sys.server_permissions
WHERE grantor_principal_id = ( SELECT principal_id FROM sys.server_principals WHERE NAME = N’LoginName’)

 

 

 

Backup script fails due to lack of network share permission

Most of people uses Ola Hallengren’s Maintenance Solution to administer their databases.  It’s easy to setup, easy to maintain. It also has dozens of parameters that you can specify and adjust maintenance plan according to your business needs.If you never heard it, you must take a look now!

We have encountered a generic problem with backup script, it was complaining about network share that we take our database backups.

We use same script on each instance, so script is good.

File share is accessible from that database host, network access is good.

We gave read/write permissions for SQL Agent service account for backup folder.

Still we get this error, so what is the problem?

The directory “\\fileshare\Network Backup Folder” does not exist. [SQLSTATE 42000] (Error 50000)

SQL Agent service account is not enough!

Both SQL Server (database engine) and Agent service accounts should have access on backup folder. Indeed after giving permissions for SQL Server service account and rebooting hosts to clear windows policy cache( if you forget to reboot or logoff/logon you will be asking WHY question a lot) it started to take backups.

Summary: If you see SQL Server can not reach a network share directory for backup or another reason, first check that both service accounts have access to that folder, then either reboot the host or log off and log on with that accounts.