Data Compare - Filtering
rkhorkp
Posts: 9
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);
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);
Comments
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 I assume that DataSynch is a string that contains a list of tables to be migrated separated by commas.
Hope that helps.
David