| Author |
Message |
markaok1
Joined: 20 Mar 2009 Posts: 11 Location: Omaha, Nebraska
|
Posted: Tue Apr 28, 2009 7:28 pm Post subject: XML and SDK |
|
|
When I was evaluating the Command line tool, I could use an XML file to set my options, servers, databases, etc. Is there a way to use the same XML file to pass in this information to the SDK?
Thanks in advance...
MarkA |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Mon May 04, 2009 5:46 pm Post subject: |
|
|
Hi Mark,
I'm sure that you can write some code that will translate an XML command file into mappings, options, ConnectionProperties, and the like, but you would have to write it, as the bit of code that does this in the command-line application is not part of the SDK.
You could more easily create and save project files to make re-usable comparisons. It's easy to load a project from disk and then use the settings to compare your schema or data. Here is some code that you can get started with: http://labs.red-gate.com/index.php/Loading_Projects%2C_Script_Folders_and_Snapshots _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
markaok1
Joined: 20 Mar 2009 Posts: 11 Location: Omaha, Nebraska
|
Posted: Tue May 05, 2009 12:05 am Post subject: XML and SDK |
|
|
Thanks Brian,
I've been struggling for a couple of days trying to use the project file. Is there a way to choose which tables get synced in the data compare? I see in the project file where there's a node called 'TableActions' that contains the tables I've selected via the GUI. The trouble is I end up syncing every table in the database, not just the one's I've selected.
Any help would be appreciated.
Thanks again for your help!
MarkA |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Tue May 05, 2009 11:04 am Post subject: |
|
|
Hi Mark,
When you read in a project file, you can apply your column and table selections using the ReplayUserActions method:
| Code: |
using System;
using System.Data.SqlClient;
using RedGate.Shared.SQL;
using RedGate.SQLCompare.Engine;
using RedGate.SQLDataCompare.Engine;
using Project = RedGate.SQLDataCompare.Engine.Project;
namespace SQLDataCompareCodeSnippets
{
public class ProjectExample
{
private const string projectName = @"testproject.sdc";
public void RunExample()
{
Project project=new Project();
project.DataSource1.ServerName = Program.DevServerName;
project.DataSource2.ServerName = Program.LiveServerName;
project.DataSource1.DatabaseName = Program.DevDatabaseName;
project.DataSource2.DatabaseName = Program.LiveDatabaseName;
project.SessionSettings = SessionSettings.Default;
project.Options = new EngineDataCompareOptions(MappingOptions.Default,ComparisonOptions.Default, SqlOptions.Default);
Console.WriteLine("Saving project");
project.SaveToDisk(projectName);
//load up the project
Project project2=Project.LoadFromDisk(projectName);
Console.WriteLine("Project loaded");
//get the two databases
using (Database db1= new Database())
using (Database db2 = new Database())
{
SchemaMappings mappings = new SchemaMappings();
//Should check if this is true
LiveDatabaseSource liveDb1 = project2.DataSource1 as LiveDatabaseSource;
ConnectionProperties sourceConnectionProperties = liveDb1.ToConnectionProperties();
//Should check if this is true
LiveDatabaseSource liveDb2 = project2.DataSource2 as LiveDatabaseSource;
ConnectionProperties targetConnectionProperties = liveDb2.ToConnectionProperties();
try
{
Console.WriteLine("Registering database " + sourceConnectionProperties.DatabaseName);
db1.RegisterForDataCompare(sourceConnectionProperties, Options.Default);
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(@"
Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are:
o The sample databases are not installed
o ServerName not set to the location of the target database
o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor
o Remote connections not enabled", sourceConnectionProperties.DatabaseName, sourceConnectionProperties.ServerName);
return;
}
try
{
Console.WriteLine("Registering database " + targetConnectionProperties.DatabaseName);
db2.RegisterForDataCompare(targetConnectionProperties, Options.Default);
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(@"
Cannot connect to database '{0}' on server '{1}'. The most common causes of this error are:
o The sample databases are not installed
o ServerName not set to the location of the target database
o For sql server authentication, username and password incorrect or not supplied in ConnectionProperties constructor
o Remote connections not enabled", targetConnectionProperties.DatabaseName, targetConnectionProperties.ServerName);
return;
}
mappings.Options = project2.Options;
mappings.CreateMappings(db1, db2);
project.ReplayUserActions(ref mappings);
//Disable any mappings here that you may want....
using (ComparisonSession session = new ComparisonSession())
{
session.Options = project2.Options;
session.CompareDatabases(db1, db2, mappings);
Console.WriteLine("Comparison run");
}
}
}
}
} |
_________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
markaok1
Joined: 20 Mar 2009 Posts: 11 Location: Omaha, Nebraska
|
Posted: Tue May 05, 2009 4:42 pm Post subject: |
|
|
Thanks Brian!
That worked perfectly...
MarkA |
|
| Back to top |
|
 |
jamest85
Joined: 21 Apr 2010 Posts: 4
|
Posted: Fri Apr 30, 2010 7:30 pm Post subject: Re: |
|
|
| markaok1 wrote: |
Thanks Brian!
That worked perfectly...
MarkA |
Hi: MarkA / Brian
I have same issue with MarkA, however, I am not so lucky here, I also used project.ReplayUserActions(ref mappings), but seems not working, can you please let me know how to add some code to prove that is working after below lines?
| Code: |
mappings.Options = project2.Options;
mappings.CreateMappings(db1, db2);
project.ReplayUserActions(ref mappings);//i only want to update I selected table in .sdc file
//Disable any mappings here that you may want....
using (ComparisonSession session = new ComparisonSession())
{
session.Options = project2.Options;
session.CompareDatabases(db1, db2, mappings);
//how to check if only comparing the selected table here?
|
Thanks a lot.
(by the way, from this post, http://www.red-gate.com/messageboard/viewtopic.php?t=10834&highlight=project+replayuseractions, Chris Auckland says " the ReplayUserActions method is no longer exposed to the user", I am using RedGate.SQLDataCompare.Engine.dll 8.1.0.7).
Jt[/code] |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Mon May 03, 2010 11:22 am Post subject: |
|
|
It's probably quickest to compare a script generated by SQL Data Compare with a script generated by SDK. _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
|