Load project options using API library

kkchankkchan Posts: 33
edited March 31, 2008 4:34AM in SQL Toolkit Previous Versions
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?

Comments

  • 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
  • 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.
  • 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
  • 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.
  • 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...
    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
  • 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
  • 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 ?
  • which would then continue (for project2)
    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
  • RichardJim

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

    Jimboh
  • If you're using the
    session.CompareDatabases(db1, db2, mappings);
    
    It should all work.

    If you're using the TableMappings you'll need something like...
    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
  • 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
  • Happy to help.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
Sign In or Register to comment.