Sylvia
Sylvia

Reputation: 2616

SQL Server 2008 - Identify which SQL Agent job is running a stored procedure

Is there any way to identify which SQL Agent job is running a stored procedure?

The reason I want this is that I'd like to have a separate step, that runs on failure, that has a stored procedure which will email the log file. To get the log file (we always use only one log file per job, not per step), I'd like to just be able to get the log file by querying the MSDB tables (select output_file_name from sysjobsteps).

I could pass a parameter with the job name to the stored procedure, but I'd like to not need to do that.

Any ideas?

thanks!

Upvotes: 4

Views: 1011

Answers (1)

Aamer Sattar
Aamer Sattar

Reputation: 46

Do you mean which job is calling the logging procedure? ie who is calling me is that what you mean? if thats the case then this may be relevant... SQL Server Agent - get my own job_id .. the failure step where you post your logging proc could use the jobid retrieved by the method described in the link... imho would work.. youd need to add a job id parm though.. and each failure step in each job would have to have two lines... one to get the id and one to call the proc.

Upvotes: 1

Related Questions