Sunday, February 26, 2012

Getting Info from Merge Agent Programmatically

Hi - I was wondering how one goes about getting infomation on agent
activity (merge and snapshot agent in my case). I would like to know when
the last synchronization took place, if it failed or not, any error
messages, etc.
How can I get this information without EM?
Thank you,
Maer
Thank you, Paul. This is exactly what I was looking for.
Do we have any control over what the name of the agent is?
Thank you - Maer
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:0ed301c4b1c8$0f7b9770$a601280a@.phx.gbl...
> Maer,
> this script will get you details of the last history for
> the merge agent called 'DH1791628-Northwind-
> NorthwindStaff-DH1791628-3'.
> It will have basic error info if an error occurs.
> If you want the detailed error info, you'll need to join
> to the MSrepl_errors table: MSmerge_history.error_id =
> MSrepl_errors.id. This table typically has several rows
> so you might want to use a cursor to add the text
> together.
> HTH,
> Paul Ibison (SQL Server MVP)
>
> declare @.agent_id int
> select @.agent_id = id from msmerge_agents where name
> = 'DH1791628-Northwind-NorthwindStaff-DH1791628-3'
> select top 1 case
> when rh.runstatus = 1 then 'Start'
> when rh.runstatus = 2 then 'Succeed'
> when rh.runstatus = 3 then 'In progress'
> when rh.runstatus = 4 then 'Idle'
> when rh.runstatus = 5 then 'Retry'
> when rh.runstatus = 6 then 'Fail'
> end as RunStatus,
> 'start_time' = convert(nvarchar(12), start_time, 112) +
> substring(convert(nvarchar(24), start_time, 121), 11, 13),
> comments
> from MSmerge_history rh
> order by timestamp desc

No comments:

Post a Comment