C# - Empty difference.ResultsStore

jasoncolbertjasoncolbert Posts: 3
edited January 24, 2007 3:30PM in SQL Toolkit Previous Versions
Hi There.

I was trying to port the DataCompare example into our software. I pretty much copied the sample so I have the following:

//// CODE START

Database db1=new Database();
Database db2=new Database();

ComparisonSession session=new ComparisonSession();
SchemaMappings mappings = new SchemaMappings();

try
{

db1.RegisterForDataCompare(new ConnectionProperties(".", "TestCompare1"), Options.Default);
db2.RegisterForDataCompare(new ConnectionProperties(".", "TestCompare2"), Options.Default);

mappings.CreateMappings(db1, db2);
session.CompareDatabases(db1, db2, mappings);

foreach (TableMapping mapping in mappings.TableMappings)
{

TableDifference difference=session.TableDifferences[mapping.Obj1.FullyQualifiedName];

foreach(Row row in difference.ResultsStore)

//// CODE END

Unfortunately, difference.ResultsStore is null. This code is identical to the demo example.


Any thoughts?

Thanks
Jason

Comments

  • By the way, the Table data for this test is simpe... yet Different:

    select * from TestCompare1..table1
    Field1
    testing

    select * from TestCompare2..table1
    Field1
    testing 2
  • Hi,

    I think this post should really be in the SQL Toolkit forum.

    The example code in the project is really very simplistic. It has been completely stripped of any exception handling and assumes that your database is absolutely perfect. It was only ever designed to be used with the Widgets databases. I think the reason you are getting this error is because it is trying to compare tables that are unable to be mapped due to a lack of a primary key.

    You could try adding this line of code to your project. This will result in only tables that are automatically mapped being compared, and this will hopefully resolve the null reference exception.

    if (mapping.Include == true){

    I put the line after
    foreach (TableMapping mapping in mappings.TableMappings)
    {

    If you want to compare tables that are not mapped. I would suggest looking at the code example for TableMappingExample. This should explain how you can add your own custom mapping to the project.
    Chris
Sign In or Register to comment.