I have a database that is replicated between 3 SQL servers
at 3 different sites over a WAN link using merge
replication.
I want to use a trigger on a table to assign a sequential
job number to records when one is needed. The trigger
recognises certain conditions and determines if an updated
row needs a job number. If it does, it updates the row
with the job number.
The job number given needs to be continuous amongst all
the offices so the best way I could come up with to do
this was to only put the trigger on 1 of the servers
(server A). That way the next job number could be stored
in a table and updated each time the trigger assigns one.
I was hoping that when updates came from the other 2
servers they would replicate to Server A, the trigger
would fire and update the record, then the new job number
would get replicated back to the other 2 servers. But that
doesn't seem to be the case.
Sometimes it works, but other times the records in Server
A are the only ones that are updated. The changes never go
back to the other servers so I end up with different data
at each server.
Has anyone got any ideas why this is happening? I'm
completely stuck. I've searched all over the internet and
can't find any help anywhere.
Failing that, does anyone have any suggestions on better
ways of doing this?
Thank you for any help!
Replication due to its asynchronous nature and the loosely consistent nature of merge replication is not ideal for this. You should be using distributed transactions for a solution like this.
However it only works when all three servers are online.
--
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Anything else I could try?
>.
>
What you could do is do a dummy update to force the
records down. To implement this selectively, your trigger
could insert a bogus value eg -999. You have a job which
looks for the value -999 and updates these records to the
correct value, in which case replication will then send
them down on the next synchronization.
HTH,
Paul Ibison
As I said though it does seem to work fine a lot of the
time. Any reason for that?
I will try what you suggested below. It's not an ideal
solution but it's worth a go.
Thanks
>.
>
sp_settriggerorder @triggername = 'MyTrigger', @order = 'first', @stmttype = 'UPDATE'
--
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
You should see following condition in the begining of every trigger of merge
replication:
if sessionproperty('replication_agent') = 1 and (select trigger_nestlevel())
= 1
This condition does the the checking which I described above.
Question is what could be done to workaround that... I would propose
modifying of the merge replication insert trigger on your jobs table in
publisher database. You could modify condition somehow that it would allow
execution of trigger when you need that.
For example something like that:
if ( sessionproperty('replication_agent') = 1 and (select
trigger_nestlevel()) = 1 ) OR ( sessionproperty('replication_agent') = 1 AND
UPDATE( job_nr_column_name ) )
Hope it helps.
--
Regards,
Kestutis Adomavicius
Consultant
UAB "Baltic Software Solutions"
"Me" <anon...@discussions.microsoft.com> wrote in message
news:1c22901c45220$4427d9f0$a101...@phx.gbl...