SQL 2000 script to kill Agent job if it overuns - sql

On a legacy SQL 2000 box that is awaiting upgrade
Does anyone have a script to kill / abort a job in SQL Agent 2000 if it over runs a set duration or overlaps with another agent job.
This is causing us a serious problem every few weeks a job overuns then locks the reindex job and that freezes our 24 / 7 server

One solution would be to add a step at the beginning of the job with which the long-running job overlaps which checks whether the long-running job is still running, and if it is issue an sp_stop_job command.
You can get the current execution status of a job using sp_help_job, but its output is not very easy to manipulate in a query.
Various methods of coercing the output of sp_help_job into a temp table in SQL 2000 are discussed here - alternatively you can query msdb.sysjobhistory to get the execution status information.

Related

One Job in SQL agent run twice in same time (like a parallel)

we have jobs in sql agent runnig schedually. We know at least about one job (scheduled every day at three different times - morning, afternoon, night) which rarely (apx one per several months) fires/runs twice in same time (like a parallel). But it is scheduled only one time in same moment. Job runs CLR stored procedure which launch console application which process some getting data and recalculating
This behaviour causes problems for us.
Why?
How could it happend?
Where is problem?
But where is reason?
Thank you for all ideas.
(Of course, we should handle it and prevent this behaviour.)
I found error in job history according to time of job execution - error 6535.
This error appears twice for this job iteration. Firstly without addtional message, secondly with additional message "The step suceeded". When I looking for information about his error 6535 - i found that this error occurs on sql server 2005, but due to select ##version, the customer use sql server 2008 R2

SQL Server Severe Error

I am executing a SQL Server Job that runs a set of SSIS packages. The run time for a full file set is about 16 hours.
I am running SQL Server 2016 in an Azure environment. The job the last two days has been finishing at 1 or 2 in the morning. When I come in the next morning my job execution window is saying the job failed but when I go in to view the job history it says everything thing in the job ran successfully. So I have no errors to go off of to try and figure this out except for these couples lines.
Is this truly an issue or is it more of just a bug? I'm lost on where to proceed.
EDIT: Here is the job history.

SQL Query - To stop/kill long running SQL job

I have a sql job who does some calculation in every 15 minutes.
Now i want to monitor this job. To check if that job is currently running and if yes then its been running for more than 10 minutes.
If it's running for more than 10 minutes then i want to stop/kill this job.
Is there any query available to do it?
Tried
EXEC msdb.dbo.sp_stop_job N'job name'
And it worked!
My best guess is you need SMO (SQL Server Management Objects) to pull this off. In particular take a look at the Job Class.

SQL Job Occurring every Less than 10 seconds

Is it possible to make Job Schedule, which will occur every less than 10 seconds?
Because Sql server doesn't allow that.
Schedule type is "Recurring" and Occurs "Daily".
Select occurs Daily and run every 10 seconds. Although keep in mind if your job takes longer than the time specified to run, the agent won't invoke it again until the running task completes.
See comments below. The UI tool doesn't allow input for less than 10 seconds. In your case you could schedule two job tasks offset by some number of seconds. The issue then is that the jobs could overlap as they are distinct tasks as far as SQL Agent knows.
I tried do something similar (SQL Server job with prcise timing), but the only reliabile way I found was custom windows service execution SQL statements.

Will a SQL Server Job skip a scheduled run if it is already running?

If you schedule a SQL Server job to run every X number of minutes, and it does not finish the previous call before the # of minutes is up, will it skip the run since it is already running, or will it run two instances of the job doing the same steps?
The SQL Server agent checks whether the job is already running before starting a new iteration. If you have long running job and its schedule comes up, it would be skipped until the next interval.
You can try this for yourself. If you try to start a job that's already running, you will get an error to that effect.
I'm pretty sure it will skip it if it is running.
Which version of SQL Server are you using? This seems like a pretty easy thing to test. Set up a job with a WAITFOR in it that inserts a single row into a table and set up the job to run twice in quick succession (shorter than the WAITFOR DELAY).
When running such a test in SQL Server 2005 it skipped the run that was overlapped.