xSQL Schema Compare SDK for SQL Server version 12
ComparisonOptions Class
Members  Example 

Provides options that determine how that database schema is compared and synchronized.
Object Model
ComparisonOptions Class
Public NotInheritable Class ComparisonOptions 
public sealed class ComparisonOptions 
public __gc __sealed class ComparisonOptions 
The following code example demonstrates how to change the options and compare two databases.
using xSQL.Schema.Core;
using xSQL.Schema.SqlServer;
using xSQL.SchemaCompare.SqlServer;
namespace xSQL.Sdk.SchemaCompare.Samples
    class Test
        public static void CompareDatabases()
            SqlServer xServer, yServer;
            SqlDatabase xDatabase, yDatabase;
            SqlSchemaCompare comparer;
            ScriptManager sqlScript;
                // create the left SQL Server object using Windows authentication
                xServer = new SqlServer(@"(local)");
                // create the right SQL Server using SQL Server authentication
                yServer = new SqlServer(@"(local)", "<user>", "<pwd>");
                // create the left database: AdventureWorks
                xDatabase = xServer.GetDatabase("AdventureWorks");
                // create the right database: AdventureWorks2008
                yDatabase = yServer.GetDatabase("AdventureWorks2008");
                // create the schema comparer
                comparer = new SqlSchemaCompare(xDatabase, yDatabase);
                // exclude some database objects
                comparer.Options.CompareUsers = false;
                comparer.Options.CompareSchemas = false;
                comparer.Options.CompareDatabaseRoles = false;
                comparer.Options.CompareApplicationRoles = false;
                // attach event handlers to these events in order to get some progress information during the schema read and compare
                comparer.LeftDatabase.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation);
                comparer.RightDatabase.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation);
                comparer.SchemaOperation += new EventHandler<SchemaOperationEventArgs>(database_SchemaOperation);
                // step 1: read the schema 
                // step 2: pair the database objects
                // step 3: compare the database schema
                // check for errors that could have occurred during the schema compare; 
                // some errors are handled quietly and do not stop the process, others that are critical throw exceptions
                // quiet errors are collected and stored into the ErrorRepository object
                if (ErrorRepository.Instance.HasErrors())
                    Console.WriteLine("Some errors occurred during the database compare");
                // check the database status; exit if no schema differences are found.
                if (comparer.SqlDatabasePair.ComparisonStatus == ComparisonStatusEnum.Equal)
                // step 4: get the T-SQL script intended for the right database; that is the script that should be executed 
                // on AdventureWorks2008 in order to make it the same as the AdventureWorks database
                sqlScript = comparer.GetRightDatabaseScript();
                // print the synchronization log
                // print the synchronization script
            catch (ConnectionException ex)
                // a connection exception
            catch (SchemaException ex)
                // a schema-read exception
            catch (SchemaCompareException ex)
                // an exception that is thrown during the schema compare
            catch (ScriptExecutionException ex)
                // an exception that is thrown during the script execution
            catch (Exception ex)
                // the fallback exception
                Console.WriteLine("An unexpected error occurred.");
        private static void database_SchemaOperation(object sender, SchemaOperationEventArgs e)
            //--exclude verbose messages
            if (e.Message.MessageType != OperationMessageTypeEnum.Verbose)
        private static void database_SnapshotOperation(object sender, SnapshotOperationEventArgs e)
            //--exclude verbose messages
            if (e.Message.MessageType != OperationMessageTypeEnum.Verbose)
Inheritance Hierarchy



Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also


ComparisonOptions Members
xSQL.SchemaCompare.SqlServer Namespace



┬ęCopyright 2022 xSQL Software. All Rights Reserved.

Send Feedback