Reputation: 5249
I have stored procedure that calls a sql job but the job is failing if 2 users make a call to the stored procedure at the same time so here is what I want to do:
I have seen some examples where you can find out if job is running but can't seem to find out to put the 2nd call on hold and only execute when the first one completes.
DECLARE @job_name NVARCHAR(MAX) = 'mySQLJob'
EXEC msdb.dbo.sp_start_job @job_name = @mySQLJob
the error I am getting is something like "job is already running"
Upvotes: 2
Views: 6142
Reputation: 108
sp_help_job can give you this information
EXEC msdb..sp_help_job @job_name = 'mySQLJob', @job_aspect = 'JOB'
current_execution_status Values - 1 Executing - 2 Waiting For Thread - 3 Between Retries - 4 Idle - 5 Suspended - 6 Obsolete - 7 PerformingCompletionActions
Upvotes: 4