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

Provides logging during the execution of the schema synchronization script.
Object Model
ExecutionLogger Class
Public NotInheritable Class ExecutionLogger 
   Inherits a.d.h
public sealed class ExecutionLogger : a.d.h 
public __gc __sealed class ExecutionLogger : public a.d.h 
The execution log stores the script fragments that are sent to and executed by SQL Server. The filename and the path of the log is determined by calling the xSQL.Schema.SqlServer.SqlPublicSettings.GetExecutionLogFile method. The execution log is named ExecLog_yyyymmdd.txt and it cannot be changed. You can change however the log folder via the property xSQL.Schema.SqlServer.SqlPublicSettings.LogFolder.

By default the logging of synchronization script is disabled. To enable it, set the comparison option ComparisonOptions.LogScriptExecution to true.

The following code shows how to execute the schema synchronization script with logging enabled.
using xSQL.Schema.Core;
using xSQL.Schema.SqlServer;
using xSQL.SchemaCompare.SqlServer;
namespace xSQL.Sdk.SchemaCompare.Samples
    class Test
        public static void SyncWithLogging()
            SqlServer server;
            SqlDatabase xDatabase, yDatabase;
            SqlSchemaCompare comparer;
            ScriptManager sqlScript;
                // create the SQL Server object
                server = new SqlServer(@"(local)");
                // create the left database
                xDatabase = server.GetDatabase("Source");
                // create the right database
                yDatabase = server.GetDatabase("Target");
                // create the comparer objects
                comparer = new SqlSchemaCompare(xDatabase, yDatabase);
                // turn on the script execution logging
                // this option creates a log file named ExecLog_yyyymmdd.txt under \Users\<current_user>\AppData\Local. 
                // the log contains the script batches that are sent to and executed by SQL Server.
                comparer.Options.LogScriptExecution = true;
                // 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 schema
                // check for errors that could have occurred during the schema compare. 
                // some errors are handled quietly and do not stop the process, those 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 Target database in order to make it the same as the Source database
                sqlScript = comparer.GetRightDatabaseScript();
                if (!sqlScript.IsEmpty())
                    //--use the event to get some progress during the script execution
                    sqlScript.SchemaScriptExecuting += new EventHandler<SchemaScriptEventArgs>(sqlScript_SchemaScriptExecuting);                    
                    //--execute the synchronization script 
                    //--check for errors
                    if (ErrorRepository.Instance.HasErrors())
                        Console.WriteLine("Some errors occurred during the script execution.");
            catch (Exception ex)
        private static void database_SchemaOperation(object sender, SchemaOperationEventArgs e)
            //--exclude verbose messages
            if (e.Message.MessageType != OperationMessageTypeEnum.Verbose)
        private static void sqlScript_SchemaScriptExecuting(object sender, SchemaScriptEventArgs e)
            Console.WriteLine("{0} {1}", DateTime.Now.ToString("HH:mm:ss"), e.Script);
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


ExecutionLogger Members
xSQL.SchemaCompare.SqlServer Namespace



┬ęCopyright 2022 xSQL Software. All Rights Reserved.

Send Feedback