I was placed in an interesting situation where I needed to manage SQL Server jobs from a web application, which would sit on a completely different server and I was only allowed to use SQL Logins (not Windows logins) to perform any SQL task, I needed a way to use an SQL server login to manage SQL Server agent jobs.
NOTE: I will be writing a tutorial on managing SQL server jobs via C# but if you’d like me to put a rush on it please let me know in the comments below.
The steps needed to set up an SQL login with sufficient permissions to manage SQL Server jobs are mentioned below.
Setting up the User:
- Run SQL Server Management Studio if not already started
- In the object explorer expand the server (if it’s not expanded already)
- Expand Security
- Right click Logins and left click New Login
- Ensure SQL Server Authentication is selected
- Setup your username and password as you like
- On the left pane, left click User Mapping
- Ensure msdb is checked in the user mapped to section
-
With msdb being selected ensure the following are checked in the Database Role Member forsection
- SQLAgentOperatorRole
- SQLAgentReaderRole
- SQLAgentUserRole
- Left click OK when you are done
Setting up the credential:
- Run SQL Server Management Studio if not already started
- In the object explorer expand the server (if it’s not expanded already)
- Expand Security
- Right click Credentials and left click New Credential
- Enter your credential name and select an identity then choose your password
- Left click OK when done
Linking the Credential and the user to SQL Server agent:
- Run SQL Server Management Studio if not already started
- In the object explorer expand the server (if it’s not expanded already)
- Expand SQL Server Agent
- Right click Proxies and left click New Proxy
- Enter a proxy name and select a credential
-
In the Active to the following subsystems section select the following:
- Power Shell
- SQL Server Integration Services package
- SQL Server Analysis Servers query
- SQL Server analysis services command
- Operating System
- ActiveX Script
- NOTE: not all of the above is needed, if you need tighter security you may remove some of the selected items as you need
- On the left panel click Properties
-
Below Proxy Account principal click Add
- Select the Principal type of SQL Login
- And tick the SQL Logins you need mapped to this credential
- Left click OK
- Left click OK
When you login to SQL management studio with that newly created user you will now see SQL Server Agent
Interesting information, very resourceful and definitely helpful thanks good job