I am using SQL Agent to schedule the exeuction of a procedure.
The first time that the procedure is executed, it runs without problems.
The second time the job (step) executes, it does not finish.
A variation of the following SQL statement tells me that the running statement is create procedure xyz...
(where xyz
is the name of the procedure that the job is supposed to run).
select
prc.loginame,
prc.program_name,
sql.text sql_text
from
sys.sysprocesses prc cross apply
sys.dm_exec_sql_text(prc.sql_handle) sql
I don't do any DDL in my procedure (or otherwise) and am wondering what causes the job to try to create the procedure and why the job hangs?
Best Answer
Seeing the procedure create statement popping up is expected behaviour here, it has nothing to do with the job agent itself. And the job step is not recreating the procedure, it is only running it.
Example
If I create this procedure:
And then run it in a query window:
Then run your query:
The create proc also shows up.
If you want more information on the procedure call you could use something like
dbcc inputbuffer
For me this returns:
Or run sp_whoisactive with the parameter
@get_outer_command
set to 1.Example result:
running sp_whoisactive might also give you more information on what part your procedure is stuck on.
The create procedure part is cleared up, the actual problem of the job hanging will be guesswork without having a reproducable example or more information.
Is the job running a query? Can parameter sniffing be an issue here?
What are the wait types when running the job? What is the amount of cpu time / reads?
Running below query (yours adapted) when the jobstep is stuck might give more information:
We would need more details to know what the actual problem is.