DbSyncProvider.SelectOverlappingScopesCommand Property

Gets or sets an IDbCommand object that contains the query or stored procedure that returns the scope name and table name for all tables in the specified scope that are also included in other scopes.

Namespace:  Microsoft.Synchronization.Data
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

public virtual IDbCommand SelectOverlappingScopesCommand { get; set; }

Property Value

Type: System.Data.IDbCommand
An IDbCommand object that contains a query or stored procedure.

The following code example specifies a command for the SelectOverlappingScopesCommand property. This command and the command that is specified for the UpdateScopeCleanupTimestampCommand property enable Sync Framework to handle cleanup appropriately in cases where a table is included in more than one scope. To view this code in the context of a complete example, see How to: Clean Up Metadata for Collaborative Synchronization (Non-SQL Server).

SqlCommand overlappingScopesCmd = new SqlCommand();
overlappingScopesCmd.CommandType = CommandType.StoredProcedure;
overlappingScopesCmd.CommandText = "Sync.sp_SelectSharedScopes";
overlappingScopesCmd.Parameters.Add("@" + DbSyncSession.SyncScopeName, SqlDbType.NVarChar, 100);
sampleDbProvider.SelectOverlappingScopesCommand = overlappingScopesCmd;

Dim overlappingScopesCmd As New SqlCommand()
With overlappingScopesCmd
    .CommandType = CommandType.StoredProcedure
    .CommandText = "Sync.sp_SelectSharedScopes"
    .Parameters.Add("@" + DbSyncSession.SyncScopeName, SqlDbType.NVarChar, 100)
End With

sampleDbProvider.SelectOverlappingScopesCommand = overlappingScopesCmd

The following code example creates the stored procedure that is called by the overlapping scopes command.

CREATE PROCEDURE Sync.sp_SelectSharedScopes
      @sync_scope_name nvarchar(100)      
   SELECT ScopeTableMap2.table_name AS sync_table_name, 
          ScopeTableMap2.scope_name AS sync_shared_scope_name
   FROM Sync.ScopeTableMap ScopeTableMap1 JOIN Sync.ScopeTableMap ScopeTableMap2
   ON ScopeTableMap1.table_name = ScopeTableMap2.table_name
   AND ScopeTableMap1.scope_name = @sync_scope_name
   WHERE ScopeTableMap2.scope_name <> @sync_scope_name