Version problems

Forum for users of SQL Toolkit 3,4,and 5

Version problems

Postby pagman » Mon Jan 21, 2008 9:33 am

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?
pagman
 
Posts: 5
Joined: Mon Jan 21, 2008 9:26 am

Postby richardjm » Mon Jan 21, 2008 10:19 am

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
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby pagman » Mon Jan 21, 2008 11:35 am

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)
pagman
 
Posts: 5
Joined: Mon Jan 21, 2008 9:26 am

Postby richardjm » Mon Jan 21, 2008 11:44 am

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
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby pagman » Mon Jan 21, 2008 11:48 am

Method Execute has to return false if there are differences. The FQN of the tables are located in an array Tables.


Code: Select all

 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;
           
        }

pagman
 
Posts: 5
Joined: Mon Jan 21, 2008 9:26 am

Postby richardjm » Mon Jan 21, 2008 11:58 am

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
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby pagman » Mon Jan 21, 2008 2:31 pm

The problem was indeed that I did not pass the fully qualified name of the tables.

It works now!

Thanks
pagman
 
Posts: 5
Joined: Mon Jan 21, 2008 9:26 am

Postby richardjm » Mon Jan 21, 2008 2:47 pm

Brilliant - out of interest what is your application for?
Richard Mitchell
Project Manager
Red Gate Software Ltd
richardjm
 
Posts: 395
Joined: Fri May 20, 2005 9:44 am
Location: Red Gate Software Ltd

Postby pagman » Mon Jan 21, 2008 2:53 pm

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
pagman
 
Posts: 5
Joined: Mon Jan 21, 2008 9:26 am


Return to SQL Toolkit Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests