Compare BACKUP to Live and Change MatchingMappings
rockywurden
Posts: 10
Problem: How do you change the MatchingMappings on a table when 1 of the databases is a SQL BACKUP.
Table3 has primary key RECID
Need to change to ROWGUID which has a unique index
map.MatchingMappings.clear
map.MatchingMappings.ADD("ROWGUID")
'Throws the following error.
*****Mappings only supports mapping objects. Parameter name: value
Thanks
Rocky
Following Code Sample see CASE TABLE3 Statement.
Dim db1 As New BackupDatabase
Dim db2 As New Database
Try
db1.RegisterForDataCompare(New String() {sFile}, Nothing)
db2.RegisterForDataCompare(New ConnectionProperties(tServer, tdatabase))
Dim mappings As New SchemaMappings
Dim map As TableMapping
mappings.CreateMappings(db1, db2)
'Exclude tables and change Index
For Each map In mappings.TableMappings
Select Case map.Obj1.Name.ToUpper
case "TABLE2"
map.Include = False
Case "TABLE3"
'This table Matching field is RECID and is the primary key.
'Need to change field to ROWGUID which has a unique index.
map.MatchingMappings.clear
map.MatchingMappings.ADD("ROWGUID")
'Throws the following error.
*****Mappings only supports mapping objects. Parameter name: value
End Select
Next map
Dim session As New ComparisonSession()
session.CompareDatabases(db1, db2, mappings)
Table3 has primary key RECID
Need to change to ROWGUID which has a unique index
map.MatchingMappings.clear
map.MatchingMappings.ADD("ROWGUID")
'Throws the following error.
*****Mappings only supports mapping objects. Parameter name: value
Thanks
Rocky
Following Code Sample see CASE TABLE3 Statement.
Dim db1 As New BackupDatabase
Dim db2 As New Database
Try
db1.RegisterForDataCompare(New String() {sFile}, Nothing)
db2.RegisterForDataCompare(New ConnectionProperties(tServer, tdatabase))
Dim mappings As New SchemaMappings
Dim map As TableMapping
mappings.CreateMappings(db1, db2)
'Exclude tables and change Index
For Each map In mappings.TableMappings
Select Case map.Obj1.Name.ToUpper
case "TABLE2"
map.Include = False
Case "TABLE3"
'This table Matching field is RECID and is the primary key.
'Need to change field to ROWGUID which has a unique index.
map.MatchingMappings.clear
map.MatchingMappings.ADD("ROWGUID")
'Throws the following error.
*****Mappings only supports mapping objects. Parameter name: value
End Select
Next map
Dim session As New ComparisonSession()
session.CompareDatabases(db1, db2, mappings)
Comments
http://help.red-gate.com/help/SQLDataCo ... /index.htm
In the TableMappingExample.cs there's a full example of changing the fields to be compared. Although as you're comparing to a backup you can only use indexes and not custom comparison keys. The call you're interested in is TableMapping.UseIndexForMapping
HTH
Project Manager
Red Gate Software Ltd