Product: | Syniti Data Replication, DBMoto |
Version: | All |
ID: | 1613 |
Summary: | A VB.NET script example to skip processing certain records |
You can set up a replication script which which aborts processing of a record based on criteria you provide. This type of script will work with all replication types (refresh, mirroring, synchronization.) Here is an example of a script which only replicates records where the value of ABBRV is < "M"
Imports Microsoft.VisualBasic
Imports DBMotoPublic
Imports DBMotoScript
Imports DBRS.GlobalScript
Namespace DBRS
Public Class ReplicationScript : Inherits IReplicationScript
Public Overrides Sub Record_onBeforeMapping(recSource As IRecord, ByRef AbortRecord As Boolean)
If recSource.GetValueAfter("ABBRV").ToString() > "M" Then AbortRecord = True
End Sub
End Class
End Namespace
In addition to filtering records via a script, for refresh replications, you can filter the records which are read by defining a Refresh Filter as follows:
- Either disable the replication you wish to change by right clicking on it in the Replication Browser or Replication Monitor and clicking on the Enable Replication item if it's checked, or stop the Data Replicator if it's running.
- Open the replication for editing by right clicking on it in the Replication Browser or Replication Monitor and choosing Replication Properties....
- Click on the Preferences tab.
- Click in the Refresh Filter Source or Refresh Filter Target values field under Refresh Options.
- Click on the "..." button at the right of the text box.
- Compose your filter in the Expression Generator.
- Click OK in the Expression Generator.
- To re-run the refresh with the refresh filter, click on the Scheduler tab, then click on the Now button.
- Click OK to close the Replication Properties dialog.
- Enable the replication again by right clicking on it and clicking on the unchecked Enable Replication entry in the menu list.
Note that the script will also run if you have defined a mirroring or synchronization replication with initial refresh. However, the filtered target table values may not behave as expected during the mirroring or synchronization portion of the replication. If you want to apply a filter for mirroring or synchronization replications, it is better to write a replication script as shown above.