string
filterTemplate =
"filter_template"
;
DbSyncScopeDescription scopeDesc =
new
DbSyncScopeDescription(filterTemplate);
scopeDesc.UserComment =
"Template for filtering based on branch id."
DbSyncTableDescription EMPLOYEE = SqlSyncDescriptionBuilder.GetDescriptionForTable(
"EMPLOYEE"
, serverConn);
scopeDesc.Tables.Add(EMPLOYEE);
//creating a provisioning template
SqlSyncScopeProvisioning serverProvisionTemplate =
SqlSyncScopeProvisioning(serverConn, scopeDesc, SqlSyncScopeProvisioningType.Template);
serverProvisionTemplate.Tables[
].AddFilterColumn(
"BRANCH_ID"
);
].FilterClause =
"[side].[BRANCH_ID] = @branchId"
SqlParameter param =
SqlParameter(
"@branchId"
, SqlDbType.VarChar, 5);
].FilterParameters.Add(param);
if
(!serverProvisionTemplate.TemplateExists(filterTemplate))
{
serverProvisionTemplate.Apply();
}
<
SqlSyncProviderScopeConfiguration
xmlns:xsd
=
"http://www.w3.org/2001/XMLSchema"
xmlns:xsi
"http://www.w3.org/2001/XMLSchema-instance"
IsTemplate
"true"
>
Adapter
Name
"[EMPLOYEE]"
GlobalName
TrackingTable
"[EMPLOYEE_tracking]"
SelChngProc
"[EMPLOYEE_selectchanges]"
SelRowProc
"[EMPLOYEE_selectrow]"
InsProc
"[EMPLOYEE_insert]"
UpdProc
"[EMPLOYEE_update]"
DelProc
"[EMPLOYEE_delete]"
InsMetaProc
"[EMPLOYEE_insertmetadata]"
UpdMetaProc
"[EMPLOYEE_updatemetadata]"
DelMetaProc
"[EMPLOYEE_deletemetadata]"
BulkTableType
"[EMPLOYEE_BulkType]"
BulkInsProc
"[EMPLOYEE_bulkinsert]"
BulkUpdProc
"[EMPLOYEE_bulkupdate]"
BulkDelProc
"[EMPLOYEE_bulkdelete]"
InsTrig
"[EMPLOYEE_insert_trigger]"
UpdTrig
"[EMPLOYEE_update_trigger]"
DelTrig
"[EMPLOYEE_delete_trigger]"
Col
name
"EMPLOYEE_ID"
type
"int"
param
"@P_1"
pk
/>
"FIRST_NAME"
"varchar"
size
"50"
null
"@P_2"
"LAST_NAME"
"@P_3"
"5"
"@P_4"
FilterParam
FilterClause
>[side].[BRANCH_ID] = @branchId</
FilterCol
>BRANCH_ID</
</
branchId =
"B0001"
branchFilteredScope =
.Format(
"{0}_Scope"
, branchId);
SqlSyncScopeProvisioning serverProvision =
SqlSyncScopeProvisioning(serverConn, scopeDesc);
serverProvision.PopulateFromTemplate(branchFilteredScope, filterTemplate);
serverProvision.Tables[
].FilterParameters[
].Value = branchId;
serverProvision.UserComment =
"Only for {0} branch."
(!serverProvision.ScopeExists(branchFilteredScope))
serverProvision.Apply();
When the provisioning is completed, a scope created on the server. Now when this step is completed if you examine the tables in “scope_info” and “scope_parameters”, again you can see two new rows created. “scope_info” will contain a row including the details of the particular provision we have done now and “scope_parameters” will contain a row including the details of parameters for the above provision. Now I am going to provision the branch database. It’s basic provision; I am getting the relevant scope from the server and applying it on the client.
DbSyncScopeDescription serverScopeDescForBranch = SqlSyncDescriptionBuilder.GetDescriptionForScope(branchFilteredScope,
SqlSyncScopeProvisioning branchProvision =
SqlSyncScopeProvisioning(branchConn, serverScopeDescForBranch);
(!branchProvision.ScopeExists(branchFilteredScope))
branchProvision.Apply();
We have done the difficult part and the next step is to do the synchronization. Once the synchronization is completed, I can see the following result on two branch databases.
Jaliya Udagedara edited Original. Comment: Formatted