4.1.21.2.3 ReplicateOffChanges()

 procedure ReplicateOffChanges(nc: DSNAME): DWORD

The ReplicateOffChanges procedure replicates all local changes in the NC to a randomly selected replication partner.

  
 targetDSAs: sequence of DSNAME
 ret: DWORD
 bReplicated: boolean
 i: integer
 msgSyncReq: DRS_MSG_REPSYNC_V1
 msgAddReq: DRS_MSG_REPADD_V2
 hDRS: DRS_HANDLE
  
 bReplicated := false
 targetDSAs := ReplicationPartners(nc)
 i := 0
 while not bReplicated
   if i ≥ targetDSAs.length then
     /* no more replication partners that host the NC! */
     return ERROR_DS_CANT_FIND_DSA_OBJ
   endif
   hDRS := BindToDSA(targetDSAs[i])
   if hDRS ≠ null then
     /* the targetDSA appears to be up. Let's try to replicate to
      * it */
     /* Invoke IDL_DRSReplicaSync to get changes from us */
     msgSyncReq.pszDsaSrc := NetworkAddress of targetDSA
     msgSyncReq.uuidDsaSrc := dc.serverGuid
     msgSyncReq.pNC := ADDR(nc)
     msgSyncReq.ulOptions := DRS_WRIT_REP
     ret := IDL_DRSReplicaSync(hDRS, 1,ADR(msgSyncReq))
     if ret = ERROR_DS_DRA_NO_REPLICA then
       /* the targetDSA does not currently have replication agreement
          (repsFrom) with this DC. Tell it to add one */
       msgAddReq.pNC := ADDR(nc)
       msgAddReq.pszSourceDsaAddress := NetworkAddress of this DC
       msgAddReq.ulOptions := DRS_WRIT_REP
       msgAddReq.pSourceDsaDN := null
       msgAddReq.pTransportDN := null
       ret := IDL_DRSReplicaAdd(hDRS, 2,ADR(msgAddReq))
     endif
     UnbindFromDSA(hDRS)
     if ret = ERROR_SUCCESS then
       /* success! */
       bReplicated := true
     endif
   endif
   i := i + 1
 endwhile
 /* if execution got here, then the changes were successfully replicated off */
 return ERROR_SUCCESS