ComparisonOptions.ForceBinaryCollation appears to be ignored
brandonagr
Posts: 4
I am using the data compare SDK (assembly version 10.2.4.113) and it seems to completly ignore my setting of the ForceBinaryCollation option. The databases are case insensitive. I attempted to decompile what its doing in session.CompareDatabases and I can't even find where it considers that option at all, so I have no idea how it could work. Is there something special in the setup required to use that option?
This is what my code looks like that is executing the comparison, and it is not finding a different between two columns that is just case
This is what my code looks like that is executing the comparison, and it is not finding a different between two columns that is just case
using (Database sourceDb = new Database()) using (Database destDb = new Database()) { var sourceConnectionString = new SqlConnectionStringBuilder(_context.SourceDatabase); ConnectionProperties sourceConnection = new ConnectionProperties(sourceConnectionString.DataSource, sourceConnectionString.InitialCatalog); Log.Trace("Registering source database {0}", sourceConnection.DatabaseName); sourceDb.RegisterForDataCompare(sourceConnection, Options.Default); var destConnectionString = new SqlConnectionStringBuilder(_context.DestinationDatabase); ConnectionProperties destConnection = new ConnectionProperties(destConnectionString.DataSource, destConnectionString.InitialCatalog); Log.Trace("Registering destination database {0}", destConnection.DatabaseName); destDb.RegisterForDataCompare(destConnection, Options.Default); SchemaMappings mappings = new SchemaMappings(); mappings.Options = redgateProject.DCOptions; mappings.Options.ComparisonOptions |= ComparisonOptions.ForceBinaryCollation; Log.Debug("Options were {0}", mappings.Options.ComparisonOptions); mappings.CreateMappings(sourceDb, destDb); var actionResult = RedGate.SQLDataCompare.Engine.DataCompareUserActions.ReplayUserActions( redgateProject.SelectTableActions, redgateProject.DataSource1, redgateProject.DataSource2, ref mappings); Log.Debug("Options after ReplayUserActions {0}", mappings.Options.ComparisonOptions); if (actionResult.Count > 0) { throw new InvalidOperationException("Unable to setup UserActions: " + string.Join(Environment.NewLine, actionResult.Select(warning => string.Format("Msg: {0} Action: {1} {2}", warning.Message, warning.UserAction.action, warning.UserAction.data)) .ToArray())); } ExecutionBlock migrationBlock = null; using (ComparisonSession session = new ComparisonSession()) { Log.Debug("Running redgate compare"); session.Options = redgateProject.DCOptions; session.Options.ComparisonOptions |= ComparisonOptions.ForceBinaryCollation; Log.Debug("Options were {0}", session.Options.ComparisonOptions); session.CompareDatabases(sourceDb, destDb, mappings); if (session.TableDifferences.All(table => table.DifferencesSummary.DifferenceCount(Row.RowType.TotalDifferent) == 0)) { Log.Info("No differences detected using {0}", project); } else { SqlProvider sp = new SqlProvider(); migrationBlock = sp.GetMigrationSQL(session, true); } Log.Debug("Redgate compare complete"); }
Comments
Here is the debug output from the TableDifferences.ResultsStore, note that it dose say expression column is <> due to the test2 vs testT2
but the sql generated by sp.GetMigrationSQL(session, true) doesn't include the expression column even though the ResultsStore shows it as different
Thanks for following up. You do indeed need to enforce the options consistently at the mappings, comparisonsession and provider to get the options applied in the mappings, results, and script creation.
I'm glad it's all sorted out.