Sql-server – T-SQL for starting Log Reader Agent

replicationsql-server-agent

I am facing a problem regarding SQL Log Reader Agent. Whenever, I start SQL Server Agent, Log Reader Agent does not start. I have to start manually.

  1. Do I have start Log Reader Agent manually every time?
  2. How can I start Log Reader Agent via T-SQL?

enter image description here

enter image description here

Best Answer

Do I have start Log Reader Agent manually every time?

That depends - what schedule is attached to the log reader agent job? The log reader agent runs as a SQL Server Agent job and typically is assigned a schedule to start when SQL Server Agent starts. This schedule might be disabled or deleted hence why you're having to start it manually.

How can I start Log Reader Agent via T-SQL?

You need to start the SQL Agent job. First, get the name of the job, then add it to this script and execute it:

EXEC msdb..sp_start_job @job_name = '<lo reader agent job name goes here>';

This shouldn't be necessary though, you just need to find and fix the problem with the schedule for this agent.

NOTE: To get the name of the job, the simplest way is to open Job Activity Monitor and look in the Category column for Repl-Log Reader.