Monday, May 14, 2012

Give control over access to SQL Server Agent

PROBLEM:
You need to give control over access to SQL Server Agent

SOLUTION:
When users who are not members of one of the following roles are connected to SQL Server in SQL Server Management Studio, the SQL Server Agent node in Object Explorer is not visible. A user must be a member of one of these fixed database roles or a member of the sysadmin fixed server role to use SQL Server Agent
  • SQLAgentUserRole
  • SQLAgentReaderRole
  • SQLAgentOperatorRole
The following command add 'LoginName' to 'SQLAgentReaderRolerole. SQLAgentReaderRole includes all the SQLAgentUserRole permissions as well as permissions to view the list of available multiserver jobs, their properties, and their history. Members of this role can also view the list of all available jobs and job schedules and their properties, not just those jobs and job schedules that they own. SQLAgentReaderRole members cannot change job ownership to gain access to jobs that they do not already own. Only the Jobs node in SQL Server Management Studio Object Explorer is visible to members of the SQLAgentReaderRole

USE [msdb]
GO
EXEC sp_addrolemember N'SQLAgentReaderRole', N'LoginName'
GO

USE [msdb]
GO
EXEC sp_droprolemember N'SQLAgentReaderRole', N'LoginName'
GO

More details:
http://msdn.microsoft.com/en-us/library/ms188283.aspx
http://msdn.microsoft.com/en-us/library/ms187901.aspx

If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!

No comments:

Post a Comment