-
February 9th, 2012, 06:41 PM
#1
Synchronizing 2 database tables , problem with primary key
Hello , i want to synchronize 2 tables with this code
Code:
SqlConnection sqlConnLocal = new SqlConnection(stgProjectConn);
SqlConnection sqlConnRemote = new SqlConnection(stgRemoteConn);
SyncOrchestrator agent = new SyncOrchestrator();
string scopeName = "test";
SqlSyncProvider sqlProviderLocal = new SqlSyncProvider(scopeName, sqlConnLocal);
SqlSyncProvider sqlProviderRemote = new SqlSyncProvider(scopeName, sqlConnRemote);
SqlSyncScopeProvisioning scopeProvisionLocal = new SqlSyncScopeProvisioning(sqlConnLocal);
if (!scopeProvisionLocal.ScopeExists(scopeName))
{
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(scopeName);
scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("mytable", sqlConnLocal));
scopeProvisionLocal.PopulateFromScopeDescription(scopeDesc);
scopeProvisionLocal.SetCreateTableDefault(DbSyncCreationOption.Skip);
scopeProvisionLocal.Apply();
}
SqlSyncScopeProvisioning scopeProvisionRemote = new SqlSyncScopeProvisioning(sqlConnRemote);
if (!scopeProvisionRemote.ScopeExists(scopeName))
{
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, sqlConnLocal);
scopeProvisionRemote.PopulateFromScopeDescription(scopeDesc);
scopeProvisionRemote.Apply();
}
agent.LocalProvider = sqlProviderLocal;
agent.RemoteProvider = sqlProviderRemote;
it works and it synchronize the data but i have one problem .
My 2 tables structure is ID,Name,Surname. (ID is primary key , Auto increasement)
Table1 values
1 myname mysurname
2 myname2 mysurname2
3 myname3 mysurname3
Table2 values
1 myname5 mysurname5
4 ... .....
5 ... ....
My code will add rows with id 4 and 5 to table1 but the 1st row (myname5 mysurname5) will replace the table1 1st row (myname mysurname) , i want to add it as new. is that possible ? i dont want to loose table1 1st value
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|