Friday, May 8, 2015

Starting SQL-job from WEB

adding a bit to dave_gona  answer; Just check status of your job before you kick it up !

DECLARE @JobName nvarchar(100) = 'YourJobName'
IF EXISTS(SELECT 1 
                  FROM msdb.dbo.sysjobs J 
                  JOIN msdb.dbo.sysjobactivity A 
                                                        ON A.job_id=J.job_id 
          WHERE J.name=@JobName 
                            AND A.run_requested_date IS NOT NULL 
                AND A.stop_execution_date IS NULL
         )
    PRINT 'The job is running!'
ELSE
    EXEC msdb.dbo.Sp_Start_job @JobName
You can create a stored procedure and pass the job name as a parameter

Glad to help! Please remember to accept the answer if you found it helpful. It will be useful for future readers having same issue.


My Profile on Microsoft ASP.NET

No comments:

Post a Comment