How can we help you today? How can we help you today?

"Object reference not set to an instance of an object."

Heres my code:
            Database liveDatabase = new Database();
            liveDatabase.RegisterForDataCompare(liveConnectionProperties);

            Database snapshotDatabase = new Database();
            snapshotDatabase.LoadFromDisk(snapshotPath);

            Differences differences = liveDatabase.CompareWith(snapshotDatabase, Options.None);

            foreach (Difference difference in differences)
            {
                difference.Selected = true;
            }

            Work work = new Work();

            work.BuildFromDifferences(differences, Options.None, false);

            ExecutionBlock executionBlock = work.ExecutionBlock;

            BlockExecutor blockExecutor = new BlockExecutor();

            blockExecutor.ExecuteBlock(executionBlock, 
                liveDatabase.ConnectionProperties.ServerName, 
                liveDatabase.ConnectionProperties.DatabaseName, 
                liveDatabase.ConnectionProperties.IntegratedSecurity, 
                liveDatabase.ConnectionProperties.UserName, 
                liveDatabase.ConnectionProperties.Password);

When run this line "work.BuildFromDifferences(differences, Options.None, false);" throws the null reference exception.

Here's the stack trace:
at RedGate.SQLCompare.Engine.Dependencies.OrderedList(IDictionary workitems)
at _32._1(Dependencies , Boolean )
at RedGate.SQLCompare.Engine.Work._1(ExecutionBlock , Options , Database , Database , _29 )
at RedGate.SQLCompare.Engine.Work.GenerateSql(Differences differences, Difference onlyDifferenceToInclude, Options options, Boolean runOnTwo)
at RedGate.SQLCompare.Engine.Work.BuildFromDifferences(Differences differences, Difference onlyDifferenceToInclude, Options options, Boolean runOnTwo)
at RedGate.SQLCompare.Engine.Work.BuildFromDifferences(Differences differences, Options options, Boolean runOnTwo)

Any thoughts?
Andy_PS
0

Comments

2 comments

  • JonathanWatts
    Hi Andy,

    It looks like you are using the RegisterForDataCompare method to load the live database. For SQL Compare schema comparisons you need to use the standard Register method instead, and supply the options you are using here too. Something like this:
    liveDatabase.Register(liveConnectionProperties, Options.None);
    

    Hope this helps.

    Regards,

    Jonathan
    JonathanWatts
    0
  • Andy_PS
    Yep your right!

    Not sure how that slipped in X(

    Well spotted and many thanks :D
    Andy_PS
    0

Add comment

Please sign in to leave a comment.