Options

Version problems

pagmanpagman Posts: 6
edited January 21, 2008 8:53AM in SQL Toolkit Previous Versions
I have made schema and data compare buildtask to include in our build on Team Foundation Server.

We cannot get the schema- and data-compare running in the same build-run because the Assembly's versions for datacompare and compare are not the same.

Is it possible to get a version compatible SQL Toolkit or are there any tricks available to get the compare and datacompare running the same process?

Comments

  • Options
    You have to use all of the assemblies from the same directory. If you're using both SQL Compare and SQL Data Compare use the dlls from the SQL Data Compare directory only.

    HTH
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Options
    When using the assemblies from the data compare folder I get the following error when I try a SQL Data compare after a schema compare

    System.ArgumentException: TableMappings.Join must called with ViewTableSuperClass arguments.
    RedGate.SQLDataCompare.Engine.TableMappings.Join(IDatabaseObject obj1, IDatabaseObject obj2)
    RedGate.SQLDataCompare.Engine.TableMappings.Join(ViewTableSuperClass viewtable1, ViewTableSuperClass viewtable2)
    Cob.Sfx.Build.Tasks.CompareDataTask.Execute()
    Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)
  • Options
    Can you give a fragment of your code as there is something strange going on with the called to TableMappings.Join by the looks of it.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Options
    Method Execute has to return false if there are differences. The FQN of the tables are located in an array Tables.

     public override bool Execute()
            {
                bool hasDifferences = false;
    
                Log.LogMessage(String.Format("Data compare between {0} and {1}.", DatabaseName1, DatabaseName2));
    
                
                Database db1 = new Database();
                Database db2 = new Database();
    
                db1.RegisterForDataCompare(new ConnectionProperties(ServerName1, DatabaseName1));
                db2.RegisterForDataCompare(new ConnectionProperties(ServerName2, DatabaseName2));
    
                TableMappings mappings = new TableMappings();
                mappings.Options.MappingOptions = MappingOptions.Default & ~MappingOptions.IncludeTimestamps;
    
                foreach (ITaskItem taskItem in Tables)
                {
                    TableMapping mapping = (TableMapping)mappings.Join((ViewTableSuperClass)db1.Tables[taskItem.ItemSpec],
                        (ViewTableSuperClass)db2.Tables[taskItem.ItemSpec]);                
                    mappings.Add(mapping);
                }
                
                ComparisonSession session = new ComparisonSession();
                session.CompareDatabases(db1, db2, mappings);
    
                foreach (TableDifference difference in session.TableDifferences)
                {
                    if (HasDifferences(difference))
                    {
                        hasDifferences = true;
                    }
                   
                }
                if (hasDifferences)
                {
                    Log.LogError("Differences in data found.");
                    return false;
                } 
                else
                {
                    Log.LogMessage("No differences in data found.");
                    return true;
                }
                
            } 
            #endregion Public Methods
    
    
            private bool HasDifferences(TableDifference tableDifference)
            {
                int differenceCount = 0;
    
                foreach (Row resultsStoreRow in tableDifference.ResultsStore)
                {
                    if (resultsStoreRow.Type != Row.RowType.Same)
                    {
                        differenceCount++;    
                    }
    
                }
                if (differenceCount > 0)
                {
                    Log.LogWarning("Table {0} has {1} data differences.", tableDifference.Name, differenceCount);
                    return true;
                }
                return false;
                
            }
    
    
  • Options
    I think this might happen if both the arguments are null. Perhaps you can put a Debug.Assert to make sure this isn't the case i.e. if the tables in your taskitem aren't in the registered databases.
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Options
    The problem was indeed that I did not pass the fully qualified name of the tables.

    It works now!

    Thanks
  • Options
    Brilliant - out of interest what is your application for?
    Richard Mitchell
    Project Manager
    Red Gate Software Ltd
  • Options
    We build applications for a transport company. Since about a year we are using team foundation server to manage source control, builds, ...

    Every build we create two databases, one reference database using VS for database professionals and a database using upgrade scripts.

    With SQL Compare we check if the upgrade database is the same as the reference database, if not, the build fails.

    Regards
    Peter
Sign In or Register to comment.