Answered by:
Sync Framework Upload only and Download only

Question
-
My Setup: I have a central database (MSSQL express 2008) and some clients (MSSQL 2008 express) .
I build a simple console sample based on http://msdn.microsoft.com/en-us/library/dd918848.aspx
I need to upload two tables (data only) from every client to the server. The two tables have identical structutre at all clients. Each table has a column named "clientid"; this id allows to identify the client sent the data.
I am using filtering in clientid column to do the job and fifferent scope for every client but I have the followin problem:
Server: provisiong ok
First client: provisioning ok, data uploaded ok
Second client: provisioning ok but the data not uploaded!
TIA
Sample code is shown below :
The sample code is shown below :
public SyncOperationStatistics uploadDataToServerFromClient(SqlConnection serverConn, SqlConnection clientConn, String scopename, String filtervalue)
{
SyncOperationStatistics syncStats = null;
try
{
DbSyncScopeDescription scopeServerUpload = new DbSyncScopeDescription(scopename);
DbSyncTableDescription table1Description = SqlSyncDescriptionBuilder.GetDescriptionForTable("TABLE1", serverConn);
scopeServerUpload.Tables.Add(table1Description);
DbSyncTableDescription table2Description = SqlSyncDescriptionBuilder.GetDescriptionForTable("TABLE2", serverConn);
scopeServerUpload.Tables.Add(table2Description);
SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning(scopeServerUpload);
serverConfig.Tables["TABLE1"].AddFilterColumn("CLIENTID");
serverConfig.Tables["TABLE1"].FilterClause = "[side].[CLIENTID] =" + filtervalue;
serverConfig.Tables["TABLE2"].AddFilterColumn("CLIENTID");
serverConfig.Tables["TABLE2"].FilterClause = "[side].[CLIENTID] =" + filtervalue;
serverConfig.SetCreateTableDefault(DbSyncCreationOption.Skip);
if (serverConfig.ScopeExists(scopename, serverConn))
{
serverConfig.SetCreateProceduresDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateTrackingTableDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateTriggersDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Skip);
serverConfig.SetPopulateTrackingTableDefault(DbSyncCreationOption.Skip);
}
if (!serverConfig.ScopeExists(scopename, serverConn))
{
if (filtervalue == "2") // if is this the second client skip all except SetCreateProceduresForAdditionalScopeDefault
{
serverConfig.SetCreateProceduresDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateTrackingTableDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateTriggersDefault(DbSyncCreationOption.Skip);
serverConfig.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create);
serverConfig.SetPopulateTrackingTableDefault(DbSyncCreationOption.Skip);
}
serverConfig.Apply(serverConn);
File.WriteAllText(scopename + "_downloadScript.txt",
serverConfig.Script(scopename));
}
DbSyncScopeDescription clientSqlDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopename, null, null, serverConn);
SqlSyncScopeProvisioning clientSqlConfig = new SqlSyncScopeProvisioning(clientSqlDesc);
if (clientSqlConfig.Tables["TABLE1"] != null)
{
clientSqlConfig.SetCreateTableDefault(DbSyncCreationOption.Skip);
}
if (clientSqlConfig.Tables["TABLE2"] != null)
{
clientSqlConfig.SetCreateTableDefault(DbSyncCreationOption.Skip);
}
if (clientSqlConfig.ScopeExists(scopename, clientConn))
{
clientSqlConfig.SetCreateProceduresDefault(DbSyncCreationOption.Skip);
clientSqlConfig.SetCreateTrackingTableDefault(DbSyncCreationOption.Skip);
clientSqlConfig.SetCreateTriggersDefault(DbSyncCreationOption.Skip);
clientSqlConfig.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Skip);
clientSqlConfig.SetPopulateTrackingTableDefault(DbSyncCreationOption.Skip);
}
if (!clientSqlConfig.ScopeExists(scopename, clientConn))
{
clientSqlConfig.Apply(clientConn);
}
SyncOrchestrator so = new SyncOrchestrator();
so.LocalProvider = new SqlSyncProvider(scopename, clientConn, null, null);
so.RemoteProvider = new SqlSyncProvider(scopename, serverConn, null, null);
so.Direction = SyncDirectionOrder.Upload;
syncStats = so.Synchronize();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return syncStats;
}
Monday, August 23, 2010 2:33 PM
Answers
-
have you tried subscribing to the ApplyChangeFailed event to see if there are any errors/conflicts being raised?
- Marked as answer by NikosKor412 Tuesday, August 24, 2010 9:38 AM
Monday, August 23, 2010 4:14 PM
All replies
-
have you tried subscribing to the ApplyChangeFailed event to see if there are any errors/conflicts being raised?
- Marked as answer by NikosKor412 Tuesday, August 24, 2010 9:38 AM
Monday, August 23, 2010 4:14 PM -
Thank you very much JuneT.
With the ApplyChangeFailed i see that i had same id's in primary key column and i had conflicts.
I change id's and now play ok!
Tuesday, August 24, 2010 9:38 AM