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

Andy_PSAndy_PS Posts: 16
edited March 5, 2007 5:48AM in SQL Compare Previous Versions
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?

Comments

  • 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
    Jonathan Watts

    -Project Manager
    -Red Gate Software Ltd
  • Yep your right!

    Not sure how that slipped in X(

    Well spotted and many thanks :D
Sign In or Register to comment.