What are the challenges you face when working across database platforms? Take the survey
Options

Confused by Database Source and Target

diesel7633diesel7633 Posts: 5 New member
I'm having trouble understanding which is the source and which is the target in the SQL Data Compare SDK.

I'm loading a project from disk. When I open the project I can see the source (DatabaseA) and target (DatabaseB) database names.

In code I'm doing...
 Project project = Project.LoadFromDisk(@"myproject.sdc");

using (Database fromDatabase=new Database())
using (Database toDatabase=new Database())
{
//debugging shows this is DatabaseA
LiveDatabaseSource fromLiveDataSource = project.DataSource1 as LiveDatabaseSource;
ConnectionProperties fromConnectionProperties = fromLiveDataSource.ToConnectionProperties();

//debugging shows this is DatabaseB
LiveDatabaseSource toLiveDataSource = project.DataSource2 as LiveDatabaseSource;
ConnectionProperties toConnectionProperties = toLiveDataSource.ToConnectionProperties();

//excluded exception handling for clarify in forum post
fromDatabase.RegisterForDataCompare(fromConnectionProperties, Options.Default);
toDatabase.RegisterForDataCompare(toConnectionProperties, Options.Default);

So essentially this is what I wanted...I want the changes to take effect on DatabaseB. When I run the statements below and view the scripts that are produced...the databases are switched in the generated SQL header.
RedGate.SQLDataCompare.Engine.DataCompareUserActions.ReplayUserActions(
                    project.SelectTableActions,
                    project.DataSource1,
                    project.DataSource2,
                    ref mappings);

using(ComparisonSession session = new ComparisonSession())
{
session.CompareDatabases(fromDatabase, toDatabase, mappings);
}

}

This is the SQL Header and the scripts seem reversed:
/*
Run this script on:

DatabaseA    -  This database will be modified

to synchronize it with:

DatabaseB

You are recommended to back up your database before running this script

Script created by SQL Data Compare version 8.1.0 from Red Gate Software Ltd at 06/29/2010 10:37:53

*/

Any thoughts?

Comments

  • Options
    diesel7633diesel7633 Posts: 5 New member
    Please disregard. I'm still learning the API and I misunderstood the bool runOnTwo for provider.GetMigrationSQL. I initially interpreted it to mean "run it" in addition to getting the SQL script back so I had it set to false, causing it to basically run the script backwards. Once set to true like in the examples, everything worked as anticipated.
Sign In or Register to comment.