Load project options using API library

Forum for users of SQL Toolkit 3,4,and 5

Load project options using API library

Postby kkchan » Sat Dec 01, 2007 11:06 am

Hi,

Just to double confirm that, If I have set all the replication option and save it. Can I use SQL toolkit C# library to load the settings from project file so that I don't have to hardcode inside my application?
kkchan
 
Posts: 23
Joined: Sat Dec 01, 2007 10:50 am

Postby richardjm » Mon Dec 03, 2007 9:37 am

If you are talking about SQL Data Compare version 6 then yes. You will have to call the function Project.ReplayUserActions() for your SchemaMappings.

HTH
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby jimboh » Fri Mar 28, 2008 2:11 pm

Please provide more DETAIL information as to how this is used .
When I suck in a project file, the resulting comparison does not have any regard for the tables and and views and column filters that i have set in the project configuration - whether the project.RepayUserActions is used or not.
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby richardjm » Fri Mar 28, 2008 3:14 pm

No need to SHOUT.

Please see a related article...

http://www.red-gate.com/MessageBoard/vi ... seractions
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby jimboh » Fri Mar 28, 2008 3:35 pm

Sorry for the unnecessary emphasis.

I have seen the reference and applied the function call you refer to in this manner:

using (ComparisonSession session = new ComparisonSession())
{
// Create the mappings between the two db
SchemaMappings mappings = new SchemaMappings();

project.ReplayUserActions(ref mappings);
// TODo 20080328 -- this is wierd !! http://www.red-gate.com/MessageBoard/vi ... seractions

mappings.Options = project2.Options;

mappings.CreateMappings(db1, db2);

session.CompareDatabases(db1, db2, mappings);

Console.WriteLine("Comparison run");

etc.
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby richardjm » Fri Mar 28, 2008 3:56 pm

OK I can see what's going on there. What you're after is creating the mappings *then* applying the user actions and you're ready to roll...
Code: Select all
using (ComparisonSession session = new ComparisonSession())
{
// Create the mappings between the two db
SchemaMappings mappings = new SchemaMappings();
mappings.Options = project2.Options;
mappings.CreateMappings(db1, db2);
project.ReplayUserActions(ref mappings);
session.CompareDatabases(db1, db2, mappings);
Console.WriteLine("Comparison run");


HTH
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby jimboh » Fri Mar 28, 2008 4:06 pm

I like your style .. I'm actually smoking arolly right now.
also you picked up on project vs project2

Unfortunately the following loop :
foreach (TableMapping mapping in mappings.TableMappings) ...
still wants to use every table in the database - rather than just the ones in the project configuration.

Thanks
Jimboh
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby jimboh » Fri Mar 28, 2008 4:23 pm

perhaps you need to see the following preliminary lines ( copied from the template)

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

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

is there some thing more that should be done first ?
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby richardjm » Fri Mar 28, 2008 4:58 pm

which would then continue (for project2)

Code: Select all
SchemaMappings mappings = new SchemaMappings();
mappings.Options = project2.Options;
mappings.CreateMappings(db1, db2);
project2.ReplayUserActions(ref mappings);
session.CompareDatabases(db1, db2, mappings);


If you yourself are looping through mappings.TableMappings you'll need to pay attention to the .Include property.

Getting there I hope.
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby jimboh » Fri Mar 28, 2008 5:09 pm

RichardJim

Please don't keep me in suspense. where and how do we use .Include and what object is it referring to ?

Jimboh
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby richardjm » Fri Mar 28, 2008 6:23 pm

If you're using the
Code: Select all
session.CompareDatabases(db1, db2, mappings);

It should all work.

If you're using the TableMappings you'll need something like...
Code: Select all
foreach (TableMapping mapping in mappings.TableMappings)
{
  if (mapping.Include)
  {
    // Do your stuff whatever that may be you're not telling me much
  }
  else
  {
    // Read the license agreement to SQL Log Rescue
  }
}


Not sure what more you're after here?
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby jimboh » Fri Mar 28, 2008 6:50 pm

richardjim

I think we are there. The use of mapping.Include property in the manner as you suggest, provides the necessary filter.

The API documentation could certainly be a bit more forthcoming in how this property is applied.

Ultimately, in this current exercise, I am trying to do an Export - similar to SQLDataCompare export - except I only want the left side and no duplicate columns in the CSV/xml file. This is mainly to get Static data for version control -- the aspect that is missing from SQL Compare scripting.

It must be getting close to close of business time in Cambridge and I thank you for your care and attention.

Until next time,

Jimboh
jimboh
 
Posts: 17
Joined: Mon Jan 29, 2007 12:23 pm
Location: Melbourne Australia

Postby richardjm » Mon Mar 31, 2008 9:34 am

Happy to help.
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd


Return to SQL Toolkit Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests