Solved

How to resolve primary Key changes with Sync Framework 2.1

Posted on 2011-09-15
8
838 Views
Last Modified: 2012-05-12
Hi,

I am synchronizing 2 databases in a one direction enviroment using Sync Framework 2.1. That means i have a "master" database and a "slave" db and i want the changes made in the master db to be downloaded to the slave db. I am only using 2 tables.
It works ok except one case. If i change the primary key in a row in the master db, this change is not reflected in the slave.

Does anybody have a clue or does anybody knows how to make the Sync FW works in those cases?

Thank you.
0
Comment
Question by:mentor360
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36546666
Typically you do not change primary keys. I would expect to see instead the creation of a new row with updated key and deletion of old row. That will sync properly to remove the slave copy of the old row while adding the new one. I guess you can do this in a INSTEAD OF UPDATE trigger that processes as normal unless the following condition is true UPDATE(PK) then you would insert a new row into your database with the new PK and other values of row and delete the original row versus updating.

The issue with UPDATE is it will come over to the slave and try to match on the PK to do update. Since the PK is now changed, you won't make any connections.

Kevin
0
 

Author Comment

by:mentor360
ID: 36546767
I have a restriction and i can't create triggers appart from the ones created by the sync framework provisioning. I thought maybe the sync framework could be configured to track the PK changes too.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36546777
How would it match to the row to change the PK? If you have other columns that act as additional unique (natural) keys, then you may be able to JOIN on those update PK ...
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:mentor360
ID: 36546860
I guess Sync Framework works different because it's able to detect and apply a DELETE. i just tested and manually deleting and inserting the row worked. But I would highly prefer the framework to work with the updates.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36546873
The framework should work for updates, just not against the primary key. Sorry.
0
 

Accepted Solution

by:
mentor360 earned 0 total points
ID: 36713070
I ended up creating a field (IDENTITY) to be the PK and added a UNIQUE index on the old PK
0
 

Author Closing Comment

by:mentor360
ID: 36898994
The was no solution I had to change my environment
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36713949
@mentor360: so to be clear for future readers - sync'ing primary key changes will not work, so your workaround is to make the column you needed to be able to change NOT a primary key. Anyway, glad you got this sorted.

Best regards and happy coding,

Kevin
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question