I would like to ask help about a weird issue I am having when trying to compare a database backup file with a live database.
First a little introduction is needed, to explain the method I am using:
I need to get the migration SQL script per table, not for the entire database at once.
To accomplish this, I am using the by your development team suggested method:
\"The correct way to do the thing they are trying to do is probably to unmap everything but the table they want to generate the script for, generate the whole script for the database with only that table mapped, then change the mappings and generate another whole-database script for the next table like that.\"
See for the whole story: http://www.red-gate.com/messageboard/vi ... hp?t=16372
Now, when using this method to compare a live database with another live database, this works perfectly.
But when using a backup file as source, the TableDifferences property of the ComparisonSession is always \"0\" in length!
Here is a part of my code:
- Code: Select all
'initialize source database from backup
Dim objSourceBackup As New SQLCompare.Engine.ReadFromBackup.BackupDatabaseSource()
Using objSourceDB As New SQLCompare.Engine.ReadFromBackup.BackupSetDatabase()
'initialize target database
Dim objTargetConnectionProperties As New SQLCompare.Engine.ConnectionProperties()
objTargetConnectionProperties.ServerName = Configuration.SQLServer_Target
objTargetConnectionProperties.DatabaseName = objDatabase.Target
If Configuration.TrustedConnection_Target Then
objTargetConnectionProperties.IntegratedSecurity = True
objTargetConnectionProperties.IntegratedSecurity = False
objTargetConnectionProperties.UserName = Configuration.UserName_Target
objTargetConnectionProperties.Password = Configuration.Password_Target
Using objTargetDB As New SQLCompare.Engine.Database()
'create mappings between source and target database
Dim objSchemaMappings As New SQLDataCompare.Engine.SchemaMappings()
objSchemaMappings.Options = objOptions
'loop through table mappings
For Each objTableMapping As SQLDataCompare.Engine.TableMapping In objSchemaMappings.TableMappings
'create new schema mappings object, but only for the current table
Dim objMappings As New SQLDataCompare.Engine.SchemaMappings(objSchemaMappings)
'compare databases (actually, just one table)
Using objComparisonSession As New SQLDataCompare.Engine.ComparisonSession()
objComparisonSession.Options = objOptions
objComparisonSession.CompareDatabases(objSourceDB, objTargetDB, objMappings)
'Now, at this point the \"objComparisonSession.TableDifferences.Count\" is always \"0\", regardless whether the two tables have differences!!!
I would like to know whether this is a bug or a limitation in the SQLDataCompare Engine.
PS: when comparing all tables at once, the TableDifferences is correctly filled, but I need the migration script per table...
PSS: I am using version 10.0.1.69 of the RedGate.SQLDataCompare.Engine.dll, but I also tried using version 10.2.4.113 and the problem still occurs.