Red Gate forums :: View topic - Sync data using project file setting
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Toolkit Previous Versions
SQL Toolkit Previous Versions forum

Sync data using project file setting

Search in SQL Toolkit Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Sat Jan 05, 2008 2:36 pm    Post subject: Sync data using project file setting Reply with quote

Hi,
I am using Data Compare to configure tables mappings, table to be sync, options, PK and etc. All of these settings are saved in Data compare project file.

How could I use SQL toolkit to sync database which will follow my settings saved in project file?

Thank you
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Mon Jan 07, 2008 10:57 am    Post subject: Reply with quote

You can use the new ReplayUserActions(ref SchemaMappings) call on the Project object in SQL Toolkit 6.0 after you've loaded the project and created the default schema mappings to use all the settings as if you were using the UI.
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Mon Jan 07, 2008 4:19 pm    Post subject: Reply with quote

Hi,
What do you meant by default schema? How to create it?
Since I already have set what tables to be sync, can I just use those tables? How to do this?

Thank you
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Mon Jan 07, 2008 4:37 pm    Post subject: Reply with quote

Just using Project.LoadFromDisk and then SchemaMappings CreateMappings after registering the databases. The SchemaMappings after that can be passed into the ReplayUserActions function and then Robert's your fathers brother.
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Tue Jan 08, 2008 4:06 pm    Post subject: Reply with quote

Hi,
What does ReplayUserActions method do?
After call ReplayUserActions(), do I need to add code to create comparisonsession, comparedatabase, execute block and etc?

Thank you
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Tue Jan 08, 2008 4:10 pm    Post subject: Reply with quote

Yes, you need all the boilerplate comparison code after the call. What it does is apply the settings from the project file to the schemamappings. e.g. Exclude Table, Set Custom Comparison Key etc. All these are stored as a 'script' in the project file to be run after the initial schemamappings have been created.

Make a few changes in the UI save the project and open it in an XML editor and you'll see what I mean.
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Thu Jan 10, 2008 5:06 am    Post subject: Reply with quote

Hi,
I have code as below. Is it correct?

Quote:
Database dbSource = new Database();
Database dbDest = new Database();

//ConnectionProperties loConnPropSource = new ConnectionProperties(toConnInfoSource.ServerName,
// toConnInfoSource.DatabaseName, toConnInfoSource.UserName, toConnInfoSource.Password);

//ConnectionProperties loConnPropDest = new ConnectionProperties(toConnInfoDest.ServerName,
// toConnInfoDest.DatabaseName, toConnInfoDest.UserName, toConnInfoDest.Password);

//dbSource.RegisterForDataCompare(loConnPropSource, Options.Default);
//dbDest.RegisterForDataCompare(loConnPropDest, Options.Default);

Project loProject = Project.LoadFromDisk(@"C:\Documents and Settings\chankk\Local Settings\Application Data\Red Gate\SQL Data Compare 6\Branch2HQ_Master.sdc");

LiveDatabaseSource loDSSource = loProject.DataSource1 as LiveDatabaseSource;
dbSource.RegisterForDataCompare(loDSSource.ToConnectionProperties());

LiveDatabaseSource loDSDest = loProject.DataSource2 as LiveDatabaseSource;
ConnectionProperties loConnPropDest = loDSDest.ToConnectionProperties();
dbDest.RegisterForDataCompare(loConnPropDest);

SchemaMappings loSchemaMappings = new SchemaMappings();
loSchemaMappings.CreateMappings(dbSource, dbDest);

List<UserActionWarning> loUserActionWarnings = loProject.ReplayUserActions(ref loSchemaMappings);

TableMappings loMappings = new TableMappings();
loMappings.CreateMappings(dbSource.Tables, dbDest.Tables);

using (ComparisonSession loSession = new ComparisonSession())
{
try
{
SessionSettings loSessionSettings = SessionSettings.IncludeDifferentRecords |
SessionSettings.IncludeRecordsInOne;
loSession.CompareDatabases(dbSource, dbDest, loMappings, loSessionSettings);
}
catch (OperationCancelledException ex)
{

}
catch (OperationAbortedException ex)
{

}

SqlProvider loSQLProvider = new SqlProvider();
ExecutionBlock loBlock = loSQLProvider.GetMigrationSQL(loSession, false);
BlockSaver loBlockSaver = new BlockSaver(@"c:\abc.sql", EncodingType.Unicode, loBlock);
loBlockSaver.SaveToFile();


BlockExecutor loExecutor = new BlockExecutor();
loExecutor.ExecuteBlock(loBlock, loConnPropDest.ServerName, loConnPropDest.DatabaseName,
loConnPropDest.IntegratedSecurity, loConnPropDest.UserName, loConnPropDest.Password);

loBlock.Dispose();
}

dbSource.Dispose();
dbDest.Dispose();
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Thu Jan 10, 2008 9:27 am    Post subject: Reply with quote

Very close. You've got the superflououous (never got stop spelling that word) lines...
Code:

TableMappings loMappings = new TableMappings();
loMappings.CreateMappings(dbSource.Tables, dbDest.Tables);


After you created your SchemaMappings and ran ReplayUserActions you were done. CompareDatabases has multiple overrides and will take the SchemaMappings directly. What you've done is effectively created a replacement table mappings without all the project settings applied and used that instead.

HTH
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Sat Jan 12, 2008 4:16 am    Post subject: Reply with quote

Hi,
Thank you for reply.
What about sync, comparison and mapping behavior? Anyway to "load" from project file?

I have a common method to do sync. I only pass project name to it and it would load project and do the rest. That why I don't have to have seperate code to manage it since already defined inside project file

Please advice.

Thank you
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Mon Jan 14, 2008 9:16 am    Post subject: Reply with quote

I think you're fine what you want to do is.

Pass routine Project File...

Load Project File
Get Databases as described in project file
Set options as in project file
Create SchemaMappings
ApplyUserActions to SchemaMappings from project file
Perform comparison
Perform synchronisation
Job Done
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
kkchan



Joined: 01 Dec 2007
Posts: 23

PostPosted: Mon Jan 14, 2008 3:44 pm    Post subject: Reply with quote

Hi

Quote:
Set options as in project file


How could I know what options set in project file?[/quote]
Back to top
View user's profile Send private message
richardjm



Joined: 20 May 2005
Posts: 389
Location: Red Gate Software Ltd

PostPosted: Mon Jan 14, 2008 4:20 pm    Post subject: Reply with quote

Project.Options perhaps? Smile
_________________
Richard Mitchell
Project Manager
Red Gate Software Ltd
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group