General discussion


Runaway SQL Server Agent Job

By kaypaul ·
How can I monitor or stop a SQL Server Agent Job
if it has ran for more than 15 mins.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Larry, In reply to Runaway SQL Server Agent ...


In order to stop an SQL Server Agent job, just use the Enterprise Manager and go to the Management, SQL Server Agent, Jobs folders. Within the "Jobs" folder, right click on the running job and select the "Stop Job" option.

Finding out what is going wrong can be tough. One place you can look for clues is in the application event log of the server. This can be accessed by right-clicking "My Computer", selecting "Manage", then "Event Viewer", then "Application". I've solved a few problems with scheduled jobs this way.

Good luck!


Collapse -

by kaypaul In reply to

Poster rated this answer.

Collapse -

by MikeBlane In reply to Runaway SQL Server Agent ...

If you're using the Scheduled Tasks in Windows, there's a checkbox to allow the task to be stopped if it has run for more than user defined number of hours or minutes.

It may also be possible to write a VBscript that is run from a scheduled task. The scheduled VBscript would have to be programmed to look for the Process name. You can get the script to wait for 15 minutes after it begins running by using the wscript.sleep statement. I'm lazy, so rather than calculating how many milliseconds that would be, I'll usually define constants in my scripts for SECONDS = 1000 and MINUTES = 60 * SECONDS. Then, I can create a 15 minute wait by using the statement Wscript.Sleep 15 * MINUTES (much like an Ada program).

After that, it would just be a matter of finding the process and killing the process with the appropriate WMI command.
'-- -----------------
Const SECONDS = 1000

wscript.sleep 15 * MINUTES
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'SQLSERVERAGENT'")

For Each objProcess in colProcessList

Note: if you are going to use a Scheduled Task to do this, remember that the task will have to have the appropriate permissions to run this script.

Also, a great resource for WMI scripting information is .

Collapse -

by kaypaul In reply to

Answer 2 is workable, but I need it in T-SQL not in WSH. Can anyone point me to a URL, which has example codings or notes.

Related Discussions

Related Forums