Product: | Syniti Data Replication - (Syniti DR, fka DBMoto) |
Version: | All |
ID: | 2026 |
Summary: | How to map MS SQL Server columns with GUID values |
When replicating from Microsoft SQL Server tables with a GUID column (column type uniqueidentifier), use the following guidelines.
GUID Value is Never NULL
If you know that the GUID value in SQL Server will *NEVER* be null, use an expression to map the field:
- Stop the Syniti DR Replication Agent/DBMoto Data Replicator or disable the replication having problems.
- Display the replication in the left hand pane of the Syniti DR/DBMoto Management Center, right click on it and choose Replication Properties....
- Click on the Mapping... button near the lower right hand corner of the Replication Properties window.
- In the Mapping dialog, display the source GUID field in the left hand pane.
- Right click on the source GUID field and, if it is not yet checked, check Use Unmapped.
- Display the target field for the GUID value in the right hand pane of the Mapping dialog.
- Right click on the target field and choose Map To Expression.
- The source field name may already be in the Expression Builder window. If not, type in the source field name surrounded by square brackets. For example, if a source field name is MYGUID, type [MYGUID] into the Expression Generator.
- Add the text ".ToString()" after the right bracket (a period followed by "ToString()"). Using the earlier example, that would be [MYGUID].ToString()
- Click OK in the Expression Generator and Mapping windows.
- Either enable the replication or start the Replication Agent/Data Replicator depending on what you did for step 1.
GUID Value Can Be NULL
If the source GUID value can be null, add a function to the Global Script and use it in the mapping expression:
- Stop the Replication Agent/Data Replicator, you cannot just disable the replication. Changing a Global Script requires that the Replication Agent/Data Replicator be stopped and restarted to process changes to the Global Script.
- Display the Metadata in the Management Center, right click on it and choose Global Script....
- In the Global Script Editor, after the line "Public Class GlobalScript : Inherits IGlobalScript" and before the first "End Class" line following the first line, enter the following.
Public Shared Function GUID_To_String(obj As Object) As Object
If obj Is Nothing Then
Return Nothing
Else
Return obj.ToString()
End If
End Function
If obj Is Nothing Then
Return Nothing
Else
Return obj.ToString()
End If
End Function
- Click on the Compile Test button (an arrow pointing down at a stack of papers) at the bottom left of the Global Script window.
- If the compile worked, click OK to close the Global Script Editor.
If the compile fails, take a screenshot and create a support ticket in the Help Center, then cancel the Global Script Editor and restart the Replication Agent/Data Replicator so that other replications continue while you are awaiting assistance.
- Display the replication in the Metadata Explorer, right click on it and choose Replication Properties....
- Click on the Mapping... button near the lower right hand corner of the Replication Properties window.
- In the Mapping dialog, display the source GUID field in the left hand pane.
- Right click on the source GUID field and, if it is not yet checked, check Use Unmapped.
- Display the target field for the GUID value in the right hand pane of the Mapping dialog.
- Right click on the target field and choose Map To Expression.
- Put the source field name in square brackets inside the function call. For example, if a source field name is MYGUID, type:
GUID_To_String([MYGUID]) - Click OK in the Expression Generator and Mapping windows.
- Start the Replication Agent/Data Replicator and check to see that the mapping works.
- If the mapping does not work, back up the metadata and create a support ticket in the Help Center. If the metadata backup is larger than 1 MB, please zip it before attaching to the ticket.