August 8, 2018 at 10:09 am
Good afternoon,
Forgive me but I am new to this, I have been given a SQL server to look at that has an SP that sends an email out if disk space gets too low. My issue is I am trying to find out what is triggering it, it has an agent job set up but the schedule is set to disabled so how is it being fired every hour?
I cannot see any triggers or any other program that could be executing it. Any ideas?
August 8, 2018 at 10:29 am
danny3291 - Wednesday, August 8, 2018 10:09 AMGood afternoon,
Forgive me but I am new to this, I have been given a SQL server to look at that has an SP that sends an email out if disk space gets too low. My issue is I am trying to find out what is triggering it, it has an agent job set up but the schedule is set to disabled so how is it being fired every hour?I cannot see any triggers or any other program that could be executing it. Any ideas?
Did you check for any alerts related to the notification? Those can also execute jobs in response.
Sue
August 8, 2018 at 12:43 pm
Check for something calling sp_start_job to run the job. A job can be executed that way without a schedule or even if the job itself is set to disabled.
August 9, 2018 at 2:19 am
Thank you both for the help, I cannot see any notifications set up and I have checked the code and I cannot see an sp_start_job. any other ideas?
August 9, 2018 at 2:25 am
SELECT
a.name AS AlertName
, j.name AS JobName
, s.step_id
, s.command
FROM msdb.dbo.sysalerts a
JOIN msdb.dbo.sysjobs j ON a.job_id = j.job_id
JOIN msdb.dbo.sysjobsteps s ON j.job_id = s.job_id
WHERE a.job_id <> '00000000-0000-0000-0000-000000000000'
John
August 9, 2018 at 2:51 am
Thank John, that returns no results, do you think It could be a PowerShell set up on the server, I don't have direct access so I cannot check at the moment.
August 9, 2018 at 3:20 am
Found that its the SQL agent, when I go into manage schedules and then find the correct one, then steps and then jobs in schedule and it shows as enabled.
How come this doesn't show enabled if I go direct into SQL agent and find that job?
August 9, 2018 at 3:25 am
This will tell you who is running the job - that may give you a clue to how the job is being run. (Don't forget to substitute in the name of your actual job.) If it doesn't, I think you'll need to run an Extended Events session to capture executions of sp_start_job.
SELECT
h.run_date
, h.run_time
, h.message
FROM msdb.dbo.sysjobhistory h
JOIN msdb.dbo.sysjobs j ON h.job_id = j.job_id
WHERE h.step_id > 0
AND j.name = 'JobWithNoSchedule';
John
August 9, 2018 at 3:33 am
danny3291 - Thursday, August 9, 2018 3:20 AMFound that its the SQL agent, when I go into manage schedules and then find the correct one, then steps and then jobs in schedule and it shows as enabled.How come this doesn't show enabled if I go direct into SQL agent and find that job?
What do you get if you run this?SELECT
j.name AS JobName
, j.enabled AS IsJobEnabled
, s.name AS ScheduleName
, s.enabled AS IsScheduleEnabled
FROM msdb.dbo.sysschedules s
JOIN msdb.dbo.sysjobschedules js ON s.schedule_id = js.schedule_id
JOIN msdb.dbo.sysjobs j ON js.job_id = j.job_id
WHERE j.name = 'JobWithNoSchedule';
John
August 9, 2018 at 3:43 am
So I have put in the name of the job and ran the script and it shows the job as enabled but the is schedule enabled column there is a 0. but when I check the history the job is running every hour.
August 9, 2018 at 4:03 am
Is the job running to the schedule that appears to be disabled (with the same frequency and at the same times)? Have you run the sysjobhistory query I posted earlier to check who's running the job? Could it be a Windows scheduled task that's doing it?
John
August 9, 2018 at 4:30 am
Just says Executed as user: NT SERVICE\SQLAgent. The step succeeded.
August 9, 2018 at 4:31 am
and yes it is running as per the created schedule its just showing as disabled.
August 9, 2018 at 4:33 am
danny3291 - Wednesday, August 8, 2018 10:09 AMGood afternoon,
Forgive me but I am new to this, I have been given a SQL server to look at that has an SP that sends an email out if disk space gets too low. My issue is I am trying to find out what is triggering it, it has an agent job set up but the schedule is set to disabled so how is it being fired every hour?I cannot see any triggers or any other program that could be executing it. Any ideas?
Could be from a Windows Scheduled Task. This would make sense as it's probably easier to write a powershell or DOS batch file to check for space and then get it to call a SQL Server stored procedure if it's out of space to send an email.
August 9, 2018 at 4:36 am
I really don't know what's happening, then. If you're more interested in fixing this than finding out why it's happening, check that the schedule isn't being used for any other jobs, then drop the schedule. If you still need it to be there so that it can be re-enabled at the flick of a switch, set the schedule up in the same way again, and disabled it.
John
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply