Data Compare - Filtering

rkhorkprkhorkp Posts: 9
edited September 7, 2006 7:39PM in SQL Toolkit Previous Versions
This is a portion of my code, where I try to filter out tables that I do not want to synch. I am getting an "Object reference not set to an instance of an object error" in the loop. So it did not finish the loop. I have about 440 tables to loop thru and it stop at 219.

Database datadb1 = new Database();
datadb1.RegisterForDataCompare(new ConnectionProperties(this.txtServer.Text.ToString(), tempDB, this.txtUser.Text.ToString(), this.txtPwd.Text.ToString()));

Database datadb2 = new Database();
datadb2.RegisterForDataCompare(new ConnectionProperties(this.txtServer.Text.ToString(), this.txtDB.Text.ToString(), this.txtUser.Text.ToString(), this.txtPwd.Text.ToString()));
RedGate.SQLDataCompare.Engine.SchemaMappings mappings = new RedGate.SQLDataCompare.Engine.SchemaMappings();

mappings.CreateMappings(datadb1, datadb2);

foreach (RedGate.SQLDataCompare.Engine.TableMapping mapping in mappings.TableMappings)
if (DataSynch.ToLower().IndexOf(";" + mapping.Obj1.Name.ToLower() + ";") < 0)
mapping.Include = false;

RedGate.SQLDataCompare.Engine.ComparisonSession session = new RedGate.SQLDataCompare.Engine.ComparisonSession();
session.Status += new StatusEventHandler(StatusCallback);

session.CompareDatabases(datadb1, datadb2, mappings);


  • Hi there,
    I would guess that
    mapping.Obj1 is not set (ie null). probably because the Table/View only exists in databb2
    I would try checking for null
    foreach &#40;RedGate.SQLDataCompare.Engine.TableMapping mapping in mappings.TableMappings&#41; 
    if &#40;&#40;mapping.Obj1 == null&#41; || &#40;DataSynch.ToLower&#40;&#41;.IndexOf&#40;";" + mapping.Obj1.Name.ToLower&#40;&#41; + ";"&#41; &lt; 0&#41; &#41;
    mapping.Include = false; 
    I assume that DataSynch is a string that contains a list of tables to be migrated separated by commas.
    Hope that helps.
  • Thanks David. That is what it is.
Sign In or Register to comment.