How to compare 2 DBases with selected tables

blaz03blaz03 Posts: 4
edited October 23, 2006 6:25AM in SQL Toolkit Previous Versions
Hi, we just bough your product, and it's great.

Now i decided to write sync data application in c# to automaticly synchronize data between two pretty large databases (each 50 GB). version of Redgate is 5.2.

My problem is that i don't know how can i set the tables which i want to synchronize.

And my second question is how to set options?
i use: SqlOptions sqlOpt = new SqlOptions();
sqlOpt = SqlOptions.DDLTriggerDisable | SqlOptions.UseTransactions..

Where do i need to set this options?

Thank you for your answers..

Best regards

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi Blaz,

    Selecting the table whose data you want to compare is a matter of setting the tablemappings:

    http://www.red-gate.com/messageboard/vi ... php?t=3060

    The gist of this is that you create the default tablemappings as shown in the Toolkit sample code and then you can loop through them and set their 'included' property on and off.

    This is how to choose individual tables.
  • Thanx for your answer,

    now, i'm having another problem, some tables can't be syncronized
    and in some tables only part of the data is syncronized.
    If i use DataCompare application i can see the diferences and i can sync them.
    But with my C# application it won't go.
    Databases all the same, tables are the same and with PKs.
    Any hint how to resolve this would be great.

    Please help :)
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    The example code creates a set of default mappings; tables can only be mapped if they have a matching unique index or constraint column. Columns with different datatypes will not be compared, either.

    You'll want to create your own custom tablemappings in code for these tables.
  • If I dont set the mappings, tables are synchronzided ok,
    but if i filter mappings, they are not..

    Code for setting mappings:
    foreach (TableMapping mapping in mappings.TableMappings)
    {
    if ((mapping.Obj1 != null) && (mapping.Obj1.FullyQualifiedName.ToLower() == "[dbo].[" + tableName + "]"))
    {
    mapping.Include=true;
    }
    else
    {
    mapping.Include = false;
    }
    }
  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi Blaz,

    From the code, I do see one problem: you are using the createmappings method to create the table mappings, then including mappings for certain tables: this leaves the tables that couldn’t be mapped automatically using the createmappings method. Those need to be mapped manually. You can see an example of this in the Data Compare examples.
    // Create the mappings between a certain table
    				TableMapping tableMapping = (TableMapping)mappings.Join(db1.Tables["[dbo].[WidgetPrices]"], db2.Tables["[dbo].[WidgetPrices]"]);
    
    				// Set the custom comparison key for the table
    				tableMapping.MatchingMappings.Clear();
    				tableMapping.MatchingMappings.Add(tableMapping.FieldMappings["WidgetID"]);
    				tableMapping.RefreshMappingStatus();
    

    This is an example of how you would manually create a mapping for a table. This manually-created mapping can then be added to the mappings created automatically using the createmappings method by using the mappings object’s Add method. Hopefully this points you in the right direction.
Sign In or Register to comment.