Options

Using Project File for Data Comparison Not returning diffs

anewhallanewhall Posts: 6
edited March 13, 2007 12:41PM in SQL Toolkit Previous Versions
Our company recently purchased the Red-Gate 5 project.
The issue I am having, if I use the Data Compare GUI with custom keys it correctly picks up the table differences. If I use the ToolKit, these differences are not being picked up. I save the project file from the DataCompare GUI and load it up through code. Do I still need to do the TableMappings for each field through code? Here is an example of the code (please note some error handling pieces are missing in order to keep this short)

project2 = Project.LoadFromDisk(projectFilePathAndName);
Console.WriteLine("Data Compare Project loaded");
//get the two databases
Database db1 = new Database();
Database db2 = new Database();

//Should check if this is true
LiveDatabaseSource liveDb = project2.DataSource1 as LiveDatabaseSource;
db1.RegisterForDataCompare(liveDb.ToConnectionProperties());

//Should check if this is true
liveDb = project2.DataSource2 as LiveDatabaseSource;
db2.RegisterForDataCompare(liveDb.ToConnectionProperties());

/* SchemaMappings mappings = new SchemaMappings();
mappings.Options = project2.Options;
// mappings.CreateMappings(db1, db2);*/
TableMappings mappings = new TableMappings();
mappings.Options = project2.Options;
mappings.CreateMappings(db1.Tables, db2.Tables);

try
{
ComparisonSession session = new ComparisonSession();
session.Options = project2.Options;
session.CompareDatabases(db1, db2, mappings, SessionSettings.Default);

if (session.TableDifferences.Count > 0)
{
SqlProvider provider = new SqlProvider();
ExecutionBlock block = provider.GetMigrationSQL(session, true);
sw.WriteLine(block.GetString());
} ....


I tried using the SchemaMappings as indicated in the code examples along with the TableMappings, but no differences were picked up.

Comments

  • Options
    Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    Unfortunately I think you do need to manually set the mappings in your code. The Data Compare project files contain some XML with settings that effectively 'replay' your mapping and unmapping actions. This code exists in the UI layer of the SQL Data Compare program, and isn't accessible using the API.
Sign In or Register to comment.