While programmatically setting up Push replication, I am noticing I am deadlocking when running sp_link_publication. The deadlock seems to be related to trigger order.
Here's what I think is going wrong:
var publisherSubscriptionParams = new Dictionary<string, object>
{
{"publication", publisherDatabase}, {"article", "all"}, {"subscriber", subscriberServer},
{"destination_db", subscriberDatabase}, {"subscription_type", "Push"}, {"sync_type", "replication support only"}, {"update_mode", "queued failover"}
};
with sp_addsubscription
var publisherPushSubscriptionAgentParams = new Dictionary<string, object> { { "publication", publisherDatabase }, { "subscriber", subscriberServer }, { "subscriber_db", subscriberDatabase }, { "subscriber_security_mode", 1 } };
with sp_addpushsubscription_agent
var subscriberParams = new Dictionary<string, object>
{
{"publisher", publisherServer}, {"publisher_db", publisherDatabase},
{"publication", publisherDatabase}, {"distributor", distributorServer}, {"security_mode", 1}
};
with sp_link_publication
sp_addsubscription adds triggers like [trg_MSsync_del_...] to my database table objects. However while this is occurring I think the command sp_link_publication clashes and forms a deadlock. Does anyone have any experience/advise with this?
I can see the triggers being added via the query:
select sys.tables.name,sys.triggers.name,sys.trigger_events.type
,sys.trigger_events.type_desc, is_first,is_last
,sys.triggers.create_date,sys.triggers.modify_date
from sys.triggers inner join sys.trigger_events
on sys.trigger_events.object_id = sys.triggers.object_id
inner join sys.tables on sys.tables.object_id = sys.triggers.parent_id
order by modify_date
After all the triggers get added, if I run sp_link_publication, no deadlock.
Any ideas?