I'd like to check the status of the agent after I start it using this statement
EXEC sp_startpublication_snapshot @publication
As I want to do a next step that needs the job to be already started.
I'd like to check the status of the agent after I start it using this statement
EXEC sp_startpublication_snapshot @publication
As I want to do a next step that needs the job to be already started.
You can also use while loop to check if agent is running or not before executing other scripts:
reference: T-SQL script to wait till status of snap agent is completed
Check its run status. Here are its values: 1 = Start.
2 = Succeed.
3 = In progress.
4 = Idle.
5 = Retry.
6 = Fail.
I do not believe there is a built-in replication stored procedure to check the snapshot agent status, I could be wrong. However, you could query MSsnapshot_history. Something like this should do the trick:
Likewise, you can check when the snapshot agent is finished:
Alternatively, you could the status of the Snapshot Agent job using sp_help_job.
After some research I got a work around way
This query returns 0 if not ready and 1 if started
Thanks all for your contribution :)