Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable Sql Server Agent using a t-sql script

Is it possible to enable or disable the sql server agent using t-sql?

like image 600
Jill Avatar asked Apr 19 '12 18:04

Jill


People also ask

How do I disable all SQL Server Agent jobs?

Go to the Job Activity Monitor and ctrl-left click on each, then right click and select disable job, or you can write a script against msdb. dbo. sysjobs and update the enabled column.

How do I let someone execute a SQL Agent job they don't own?

There are only two ways that someone can have permission to execute a SQL Agent job. You must either own the job, or be a member of the role SQLAgentOperatorRole (found in msdb). Unfortunately SQLAgentOperatorRole grants permissions to run any job (among other things).

How do I enable an agent in SQL?

To configure SQL Server AgentIn Control Panel, select System and Security, select Administrative Tools, and then select Local Security Policy. In Local Security Policy, select the chevron to expand the Local Policies folder, and then Select the User Rights Assignment folder.

How do I fix SQL Server Agent stopped automatically?

Check the SQL error log for any related stack dumps or messages. This exception forces SQL Server to shutdown. To recover from this error, restart the server (unless SQLAgent is configured to auto restart).


2 Answers

exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 0 --Disable exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 1 --Enable 
like image 55
Russell Fox Avatar answered Sep 23 '22 06:09

Russell Fox


You can use this to set it ON or OFF

   EXEC xp_servicecontrol N'stop',N'SQLServerAGENT'    EXEC xp_servicecontrol N'start',N'SQLServerAGENT' 
like image 24
Jean-Philippe Vankemmel Avatar answered Sep 24 '22 06:09

Jean-Philippe Vankemmel