0
votes

I'm trying to synchronize an Sql Server database with SQL Azure Database (please be patient 'cause I don't fully understand Sync Framework). These are the requirements:

  • First: synchronize 1 table from Sql Azure to Sql Server
  • Second: synchronize 13 other tables (including the table I mentioned in the first step) from Sql Server to Azure. I've created a console application, and this is the code:

1.I create one scope with the 13 tables:

DbSyncScopeDescription myScope = new DbSyncScopeDescription("alltablesyncgroup");
DbSyncTableDescription table = qlSyncDescriptionBuilder.GetDescriptionForTable("tablename", sqlServerConn);
myScope.Tables.Add(table); //repeated 13 times.

2.I Provision both data bases:

SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(sqlAzureConn,myScope);
if (!sqlAzureProv.ScopeExists("alltablesyncgroup"))
{
 sqlAzureProv.Apply();
}
SqlSyncScopeProvisioning sqlServerProv = new SqlSyncScopeProvisioning(sqlServerConn, myScope);
if (!sqlServerProv.ScopeExists("alltablesyncgroup"))
{
  sqlServerProv.Apply();          
}

3.I create the SyncOrchestrator with the SyncDirectionOrder.Download to sync the firts table:

SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);
SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);
SyncOrchestrator orch = new SyncOrchestrator
{
  RemoteProvider = new SqlSyncProvider(scopeName, sqlAzureConn),
  LocalProvider = new SqlSyncProvider(scopeName, sqlServerConn),
  Direction = SyncDirectionOrder.Download
};
orch.Synchronize();

4.Later, I use the same function only changing the direction SyncDirectionOrder.Upload to sync the 13 remaining tables

SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);
SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);
SyncOrchestrator orch = new SyncOrchestrator
{
  RemoteProvider = new SqlSyncProvider(scopeName, sqlAzureConn),
  LocalProvider = new SqlSyncProvider(scopeName, sqlServerConn),
  Direction = SyncDirectionOrder.Upload
};
orch.Synchronize();

Now, here is the thing, obviously I'm doing it wrong 'cause when I download, the syncStats shows that a lot of change have been applied BUT I can't see it reflected on any data base and when I try to execute the Upload sync it seems to be going into a loop 'cause the Upload process doesn't stop.

Thanks!!!

1

1 Answers

0
votes

first, you mentioned you only want to sync one table from Azure to your SQL Server but you're provisioning 13 tables in the scope. if you want one table, just provision a scope with one table. (e.g. one scope for the download with table, one scope for the upload with the rest of the tables)

to find out why rows are not synching, you can subscribe to the ApplyChangeFailed event for both sides, and check if there are conflicts or errors being encountered.

or you can enable Sync Framework tracing in verbose mode so you can see what's happening underneath.