Showing posts with label merge. Show all posts
Showing posts with label merge. Show all posts

Sunday, March 11, 2012

Complicated Merge Replication/Trigger problem

Hi all, we have a complicated merge replication/trigger problem.
Ill try to explain the setup first...
We have 2 SQL Server 2005 servers (called Server1 and Server2 for this
example)
On each Server there is an identical database (called SalesData for
this example) which contains 2 related tables (called A and B for this
example).
Tables A and B are related in that when a record is updated in table A,
a trigger (called trUpdateB) fires which updates a related record in
table B.
The trigger trUpdateB is marked as 'Not For Replication'.
Now we have Merge replication set up between Server1.SalesData
(Publisher) and Server2.SalesData (Subscriber) which replicates changes
back and forth between the 2 databases.
When we update a record in table Server1.SalesData.A the trigger fires
and the replication takes place, so we get changes in both A and B
replicated to Server2.SalesData.
And vice versa, when we update a record in table Server2.SalesData.A
the trigger fires and the replication takes place, so we get changes in
both A and B replicated to Server1.SalesData.
So far, all works as expected.
The problem is this...
We create a conflict - updates are made to Server1.SalesData.A and
Server2.SalesData.A at about the same time.
We are using the default conflict resolver so the Publisher (Server1)
should win.
However when I look at the Replication Monitor it says that the there
was 1 change downloaded to the subscriber (table A's update) and 1
change uploaded to the publisher (table B's update - created by the
trUpdateB trigger).
I expected to see both the 2 changes downloaded to the subscriber.
The Replication Conflict Viewer only reports 1 conflict (for table A)
which was resolved as expected (Publisher wins).
I expected to see 2 conflicts (one for each table) both resolved in
favour of the Publisher.
Can anyone explain where I am going wrong here, either in my
implementation of merge replication or in my expectation of how it
should work?
Thanks in advance, any help is greatly appreciated.
Bazza
This is hard to figure out. I take it you have column level tracking -
otherwise you would have no conflict.
I would do the following. On the Subscriber update A. See the update in B.
Verify that there are corresponding entries in msmerge_contents for both the
updates.
Repeat this on the publisher. Verify that everything is in place. Now do the
sync.
There should be 2 downloads. Both from the publisher to the subscriber.
There should be between one and two conflicts depending on the columns
changed.
Run profiler on the subscriber to see what it is doing.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"bazza" <bazzaontour2002@.hotmail.com> wrote in message
news:1164110590.894357.308440@.m73g2000cwd.googlegr oups.com...
> Hi all, we have a complicated merge replication/trigger problem.
> Ill try to explain the setup first...
> We have 2 SQL Server 2005 servers (called Server1 and Server2 for this
> example)
> On each Server there is an identical database (called SalesData for
> this example) which contains 2 related tables (called A and B for this
> example).
> Tables A and B are related in that when a record is updated in table A,
> a trigger (called trUpdateB) fires which updates a related record in
> table B.
> The trigger trUpdateB is marked as 'Not For Replication'.
> Now we have Merge replication set up between Server1.SalesData
> (Publisher) and Server2.SalesData (Subscriber) which replicates changes
> back and forth between the 2 databases.
> When we update a record in table Server1.SalesData.A the trigger fires
> and the replication takes place, so we get changes in both A and B
> replicated to Server2.SalesData.
> And vice versa, when we update a record in table Server2.SalesData.A
> the trigger fires and the replication takes place, so we get changes in
> both A and B replicated to Server1.SalesData.
> So far, all works as expected.
> The problem is this...
> We create a conflict - updates are made to Server1.SalesData.A and
> Server2.SalesData.A at about the same time.
> We are using the default conflict resolver so the Publisher (Server1)
> should win.
> However when I look at the Replication Monitor it says that the there
> was 1 change downloaded to the subscriber (table A's update) and 1
> change uploaded to the publisher (table B's update - created by the
> trUpdateB trigger).
> I expected to see both the 2 changes downloaded to the subscriber.
> The Replication Conflict Viewer only reports 1 conflict (for table A)
> which was resolved as expected (Publisher wins).
> I expected to see 2 conflicts (one for each table) both resolved in
> favour of the Publisher.
> Can anyone explain where I am going wrong here, either in my
> implementation of merge replication or in my expectation of how it
> should work?
> Thanks in advance, any help is greatly appreciated.
> Bazza
>
|||Thanks for your reply Hilary
No, we are using Row Level tracking. However Im changing the same
column on the same record in table A on both servers so it shouldnt
make any difference should it? Whether Im using Row or Column level
tracking Im going to cause a conflict as far as I understand it? Please
correct me if Im wrong.
Ok, I tried your suggestion. After making the changes on the publisher
and the subscriber there were 2 entries in the msmerge_contents in each
database. The 'rowguid' column shows the correct value for the 2
records (one from A and one from B). So everything seems to be in place
at this point.
Then I started the sync and got the same result as before! 1 download
(table A) and 1 upload (B) is showing in replication monitor. There is
1 conflict (as before) showing in replication conflict viewer which was
resolved in favour of the Publisher (as before)
Something very strange is going on but I cant quite figure it out.
Curiously when I disabled the trigger (on both servers) and made the
change to table A (on both) then simulated the trigger firing by
manually changing the record in table B (on both), it all works as
expected. 2 downloads, 0 uploads, 2 conflicts resolved in favour of the
publisher (1 on each table).
It appears to be something to do with the trigger - is it conflicting
with the Merge triggers in some way, do you think?
Bazza
Hilary Cotter wrote:[vbcol=seagreen]
> This is hard to figure out. I take it you have column level tracking -
> otherwise you would have no conflict.
> I would do the following. On the Subscriber update A. See the update in B.
> Verify that there are corresponding entries in msmerge_contents for both the
> updates.
> Repeat this on the publisher. Verify that everything is in place. Now do the
> sync.
> There should be 2 downloads. Both from the publisher to the subscriber.
> There should be between one and two conflicts depending on the columns
> changed.
> Run profiler on the subscriber to see what it is doing.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
>
> "bazza" <bazzaontour2002@.hotmail.com> wrote in message
> news:1164110590.894357.308440@.m73g2000cwd.googlegr oups.com...
|||Just to make a wild guess. ensure that you are using the custom
resolver (publisher wins) on both the tables A and B.
On Nov 22, 10:57 pm, "bazza" <bazzaontour2...@.hotmail.com> wrote:[vbcol=seagreen]
> Thanks for your reply Hilary
> No, we are using Row Level tracking. However Im changing the same
> column on the same record in table A on both servers so it shouldnt
> make any difference should it? Whether Im using Row or Column level
> tracking Im going to cause a conflict as far as I understand it? Please
> correct me if Im wrong.
> Ok, I tried your suggestion. After making the changes on the publisher
> and the subscriber there were 2 entries in the msmerge_contents in each
> database. The 'rowguid' column shows the correct value for the 2
> records (one from A and one from B). So everything seems to be in place
> at this point.
> Then I started the sync and got the same result as before! 1 download
> (table A) and 1 upload (B) is showing in replication monitor. There is
> 1 conflict (as before) showing in replication conflict viewer which was
> resolved in favour of the Publisher (as before)
> Something very strange is going on but I cant quite figure it out.
> Curiously when I disabled the trigger (on both servers) and made the
> change to table A (on both) then simulated the trigger firing by
> manually changing the record in table B (on both), it all works as
> expected. 2 downloads, 0 uploads, 2 conflicts resolved in favour of the
> publisher (1 on each table).
> It appears to be something to do with the trigger - is it conflicting
> with the Merge triggers in some way, do you think?
> Bazza
> Hilary Cotter wrote:
>
>
>
>
>
>
>
>
>
|||Thanks Udit
However, we are using the default resolver (and the subscriber priority
is set to 75.00) so the Publisher should win all conflicts as I
understand it - correct?
Ok, well Ive moved on slightly with the problem.
Ive realized that although the trigger is firing as expected, it doesnt
actually make any changes to the record in table B - the column value
is updated to the same as the existing value.
Therefore I can now understand why there is only 1 conflict.
However I still dont understand why there is 1 upload and 1 download -
I would now expect there just to be the 1 download and 0 uploads.
Any ideas?
Udit Ghai wrote:[vbcol=seagreen]
> Just to make a wild guess. ensure that you are using the custom
> resolver (publisher wins) on both the tables A and B.
>
> On Nov 22, 10:57 pm, "bazza" <bazzaontour2...@.hotmail.com> wrote:
|||You are right that there is one upload when actually you would expect 0
uploads. However even an update to the same value is an update. So I would
say that one would expect 1 upload attempted which should result in a
conflict and 1 download with the publisher update winning (even though there
is no real update).
However since there are no real updates, this may seem cosmetic. But if you
had real updates then I do see the expected behavior -- 2 updates attempted
which will resut in 2 conflicts and the 2 publisher rows in A and B
downloaded.
Note that you dont need to have 2 tables and triggers to see this behavior.
Just a simple table and try updating c1=c1 on both publisher and subscriber.
At this point, I would say that if this doesnt cause you pain in your logic,
its livable. We can address this in the next release of SQL Server.
Hope that helps
--Mahesh
[ This posting is provided "as is" with no warranties and confers no
rights. ]
"bazza" <bazzaontour2002@.hotmail.com> wrote in message
news:1164290161.387477.142820@.l39g2000cwd.googlegr oups.com...
> Thanks Udit
> However, we are using the default resolver (and the subscriber priority
> is set to 75.00) so the Publisher should win all conflicts as I
> understand it - correct?
> Ok, well Ive moved on slightly with the problem.
> Ive realized that although the trigger is firing as expected, it doesnt
> actually make any changes to the record in table B - the column value
> is updated to the same as the existing value.
> Therefore I can now understand why there is only 1 conflict.
> However I still dont understand why there is 1 upload and 1 download -
> I would now expect there just to be the 1 download and 0 uploads.
> Any ideas?
>
> Udit Ghai wrote:
>
|||Thanks very much Mahesh.
It doesnt cause any pain, but Im really just trying to satisfy myself
that Merge replication works as I understand it, as we are about to
deploy this a large, muti user system. What seem like little
inconveniences like this, might cause bigger problems in the live
system.
Anyway, Im still not completely happy I understand. So you are saying
that because I am doing an UPDATE in the trigger, even if I just set
the value to be the same as existing, this will still result in a merge
action?
If so, then I would still expect 2 downloads and 0 uploads, with 2
conflicts resolved in favour of the publisher, wouldnt I?
I am still getting, 1 download (table A), 1 upload (table B) and 1
conflict resolved in favour of the publisher (for the table A update).
I dont believe I should be getting the 1 upload at all.
When the merge engine tries to upload the update to table A it gets a
conflict and the publisher wins so the upload doesnt happen - thats as
I expect.
However when the merge engine tries to upload the update to table B
(created by the trigger) it doesnt appear to get a conflict and the
upload DOES happen. This is not right in my opinion.
If you like I can script out the tables with the trigger?
Thanks for your time
Bazza
Mahesh [MSFT] wrote:[vbcol=seagreen]
> You are right that there is one upload when actually you would expect 0
> uploads. However even an update to the same value is an update. So I would
> say that one would expect 1 upload attempted which should result in a
> conflict and 1 download with the publisher update winning (even though there
> is no real update).
> However since there are no real updates, this may seem cosmetic. But if you
> had real updates then I do see the expected behavior -- 2 updates attempted
> which will resut in 2 conflicts and the 2 publisher rows in A and B
> downloaded.
> Note that you dont need to have 2 tables and triggers to see this behavior.
> Just a simple table and try updating c1=c1 on both publisher and subscriber.
> At this point, I would say that if this doesnt cause you pain in your logic,
> its livable. We can address this in the next release of SQL Server.
> Hope that helps
> --Mahesh
> [ This posting is provided "as is" with no warranties and confers no
> rights. ]
> "bazza" <bazzaontour2002@.hotmail.com> wrote in message
> news:1164290161.387477.142820@.l39g2000cwd.googlegr oups.com...
|||Bazza,
Yes, I agree that update to B should conflict and you should not see an
update.
However if you make a real update (instead of updating c1=c1 or updating to
the same value, as you were doing previously), you should see a conflict and
should not see an upload happen.
Can you try that and let me know if you are still seeing an upload. Then it
can become an issue. Otherwise it doesnt matter because you are updating the
value to the same value at both sides and so essentially there is no
difference in data whether the upload happens or not.
Hope that helps
--Mahesh
[ This posting is provided "as is" with no warranties and confers no
rights. ]
"bazza" <bazzaontour2002@.hotmail.com> wrote in message
news:1164362204.094165.260040@.l12g2000cwl.googlegr oups.com...
> Thanks very much Mahesh.
> It doesnt cause any pain, but Im really just trying to satisfy myself
> that Merge replication works as I understand it, as we are about to
> deploy this a large, muti user system. What seem like little
> inconveniences like this, might cause bigger problems in the live
> system.
> Anyway, Im still not completely happy I understand. So you are saying
> that because I am doing an UPDATE in the trigger, even if I just set
> the value to be the same as existing, this will still result in a merge
> action?
> If so, then I would still expect 2 downloads and 0 uploads, with 2
> conflicts resolved in favour of the publisher, wouldnt I?
> I am still getting, 1 download (table A), 1 upload (table B) and 1
> conflict resolved in favour of the publisher (for the table A update).
> I dont believe I should be getting the 1 upload at all.
> When the merge engine tries to upload the update to table A it gets a
> conflict and the publisher wins so the upload doesnt happen - thats as
> I expect.
> However when the merge engine tries to upload the update to table B
> (created by the trigger) it doesnt appear to get a conflict and the
> upload DOES happen. This is not right in my opinion.
> If you like I can script out the tables with the trigger?
> Thanks for your time
> Bazza
> Mahesh [MSFT] wrote:
>

Thursday, March 8, 2012

Complex SSIS Lookup/Merge Join Using NK and Dates

I had this (what seems to be a) simple question asked today and I'm afraid I didn't like my answer. Does anyone know the proper answer to this one:

Any ideas on how I can constrain a lookup or merge join based on the dimension row's effective and expired dates so three criteria are needed as follows:
1. DataStagingSource.ModifyDate < DataWarehouseDimension.RowExpiredDate AND
2. DataStagingSource.ModifyDate >= DataWarehouseDimension.RowEffectiveDate AND
3. DataStagingSource.NaturalKey = DataWarehouseDimension.NaturalKey

-- Brian

Hi Brian. I would go ahead and join based on your NaturalKey, then use a secondary step such as a Conditional Split to filter based on the dates.

Jay|||Brian, I just came across the same problem. Any chance you can post the code example to accomplish this? thanks|||

There's a possible option here: http://blogs.conchango.com/jamiethomson/archive/2006/03/29/3294.aspx

Beware though, no data gets cached in memory.

-Jamie

Complex SSIS Lookup/Merge Join Using NK and Dates

I had this (what seems to be a) simple question asked today and I'm afraid I didn't like my answer. Does anyone know the proper answer to this one:

Any ideas on how I can constrain a lookup or merge join based on the dimension row's effective and expired dates so three criteria are needed as follows:
1. DataStagingSource.ModifyDate < DataWarehouseDimension.RowExpiredDate AND
2. DataStagingSource.ModifyDate >= DataWarehouseDimension.RowEffectiveDate AND
3. DataStagingSource.NaturalKey = DataWarehouseDimension.NaturalKey

-- Brian

Hi Brian. I would go ahead and join based on your NaturalKey, then use a secondary step such as a Conditional Split to filter based on the dates.

Jay|||Brian, I just came across the same problem. Any chance you can post the code example to accomplish this? thanks|||

There's a possible option here: http://blogs.conchango.com/jamiethomson/archive/2006/03/29/3294.aspx

Beware though, no data gets cached in memory.

-Jamie

Friday, February 17, 2012

compensating delete on replication database!

Hi
I have Merge Publication with just one Subscriber running on SQL 2000
which has been Service packed fully.
Looking at the previous posts I did uncheck 'Enforce relationship for
replication' on the Table Relationships hoping that the deletion of
records will not happen.
But for some unknown reason the records in the FK relationship is
deleted, which is causing all sorts of problems. There are no Triggers
on the database, and I could not find a pattern for the deletion it
happens randomly.
E.G. We have a 'Contacts' and 'Addresses' Table, one contact can have
more than 1 address. But for some reason the addresses are being deleted
for the contact, i am not sure where it is happening whether in
Subscriber or Publisher, but we loose the record.
Does any one has a good solution for this?
Thanks in advance.
Regards
Laks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
Do you have any user triggers at all?
Perhaps you are experiencing the compensating commands situation :
http://support.microsoft.com/default...Product=sql2k?
Rgds,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)!
|||Thanks Paul for the link. But I do not have any user triggers at all?
Since the 'Enforce relationship for replication' is unchecked, I am a
bit puzzled about how this is happening.
Can I apply the hotfix (the link you have sent) to the production
server? Is it safe?
Thanks once again.
Regards
Laks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||Hi Paul
The Hotfix is available only in SP4 Beta and not sure when it is going
to be released. In the meantime the database is loosing the records all
the way through. Can you suggest any intermediate solutions? somethings
I need to check etc..
Thanks
Laks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||The two suggestions weren't related - user triggers was just one other
posibility.
If it is a compensation issue, you should be able to reproduce. An address
added successfully at one site will be deleted if it cannot be applied at
the other due to a PK/FK error, constraint error etc. So, you need to check
that the schemas are identical wrt these tables (SQLCompare?). If you can
find an address that repeatedly gets removed then tracking/removing the
constraint should be simple.
HTH,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)!
|||Hi Paul
Thanks for the reply. There is not pattern these records are deleted and
I am not able to re-create it as well.
The Addresses Table has 2 FK relationship one to the AddressType Table
and one to the Contact Table were the records are all present. It is
only the Address records that gets deleted.
Any other areas to look into, please...
Thanks
Laks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
|||Hi Paul
I am really sorry, there is a Trigger created by another developer on
the Addresses Table, which maintaines the Ref. Intergerity. Could this
be the cause for this 'compensating deletion', if so how to overcome
this, do we need to remove the triggers?
Regards
Laks
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

Compensating Changes - Deletes Good Rows From a Table?

We have some tables set up doing merge replication, and just came across
http://support.microsoft.com/default...&Product=sql2k
Is this gist of this, that when a compensating change condition exists, that
potentially good rows that cannot be replicated out, are instead DELETED
from the source table?
Is it logged somewhere when this has happened, or is there a way to monitor
it otherwise?
Thanks!
They are logged as conflicts but remain in the publisher/subscriber.
So if you insert a row with the same pk value in the publisher and
subscriber, when the sync happens the rows remain in the publisher and
subscriber.
If you update a row on the subscriber and delete it on the publisher, the
row remains updated on the subscriber and is not deleted there and remains
deleted on the publisher.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Art Vandelay" <artvandelay92k@.hotmail.com> wrote in message
news:OR2q7S6%23FHA.264@.tk2msftngp13.phx.gbl...
> We have some tables set up doing merge replication, and just came across
> http://support.microsoft.com/default...&Product=sql2k
> Is this gist of this, that when a compensating change condition exists,
> that potentially good rows that cannot be replicated out, are instead
> DELETED from the source table?
> Is it logged somewhere when this has happened, or is there a way to
> monitor it otherwise?
> Thanks!
>
>
>