Tables in a sync scope must be ordered
Before doing synchronization using the Microsoft Sync Framework 2.0 it is required to provision a sync scope. In the scope you define which tables and columns are synchronized and specify any filters if required.
Detailed instruction can be found at the following resources:
Provisioning for Synchronization (SQL Server),
Walkthrough: Defining Filtered Scope and Provisioning Server Database,
Walkthrough: Defining Scope and Provisioning a Server Database
Yet one important detail is missing in all these references: The order of the tables in a scope.
When creating a scope for synchronizing multiple tables with parent child relationship the child must be declared first.
var scopeDesc = new DbSyncScopeDescription(scopeName);
scopeDesc.Tables.Add(
SqlSyncDescriptionBuilder.GetDescriptionForTable(chiledTable, serverConn));
scopeDesc.Tables.Add(
SqlSyncDescriptionBuilder.GetDescriptionForTable(parentTable, serverConn));
If you fail to do so the sync process will crash with OutOfMemory Exception.
It is not documented but multi table scopes assume that the tables are ordered according to the database constrains. If this assumption breaks loading the scope in the GetKnowledge method (In the beginning of the sync process) creates a huge memory block and the process fails.
I spent quite some time with this bug.
Manu