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

2

35

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

Homiletics answered 19/4, 2012 at 18:3 Comment(0)
A
55
exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 0 --Disable
exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 1 --Enable
Abduction answered 19/4, 2012 at 18:8 Comment(2)
Thanks! is there a way to enable/disable the agent itself too?Homiletics
You're welcome! And yes, google xp_servicecontrol (I've never use it).Abduction
J
7

You can use this to set it ON or OFF

   EXEC xp_servicecontrol N'stop',N'SQLServerAGENT'
   EXEC xp_servicecontrol N'start',N'SQLServerAGENT'
Jagged answered 8/5, 2018 at 19:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.