xSQL Object Command Line utility allows for comparing the schema
of SQL Server databases via the command line. With the xSQL Object
Command Line you can:
The following files are required to run the Command Line:
The command line options control the general behavior of the xSQL Object Command Line utility such as the mode of operation (quiet), file encoding, the location of the log and error files. Each option has a short and a long form. For example /q and /quiet specify the "quiet" mode which suppresses all the comparison messages from being displayed on the screen or saved to a file. The value of the option should be separated from the option switch using a colon, not a space. For example /l:c:\compare.log saves all comparison messages to the output file c:\compare.log.
The schema comparison options and preferences on the other hand are specified via an xml configuration file. When the same command line option exists for an xml-specified parameter, the command line value has priority over the one specified in the xml file.
xSQL Object Command Line utility supports the following argument and options:
| Argument | Description |
|---|---|
| Xml File | The xml configuration file that contains the comparison preferences. |
| Option | Description |
|---|---|
| ? | Displays the help screen. |
| /v[alidate] | Performs validation of the xml configuration file. No comparison is performed. |
| /l[ogfile]:filename | Specifies the name of log file where comparison messages should be saved. |
| /t /logtype:File|WindowsLog | Indicates the type of logging for schema errors. Supported options are disk file (File) or Windows log (WindowsLog). |
| /e[rror]:filename | Specifies the name of the error log. Depending on the /t
option, this can indicate a disk file or Windows log.
|
| /o[verride] | Overrides all output files. |
| /q[uiet] | Indicates the quite mode, which suppresses all comparison messages from being displayed on the screen or saved to the log file. |
| /en[coding] | Specifies the encoding of the output files. The supported options are UTF7, UTF8, ASCII, Unicode and ANSI. The default encoding is ANSI. |
Due to the large number of arguments, xSQL Object Command Line utility uses an xml configuration file for all the comparison options.
The Xml configuration file allows you to:
The xml file groups the comparison parameters and options into the following sections:
| Section | Description |
|---|---|
| Database <LeftDatabase> <RightDatabase> |
Contains the databases to compare. The Command Line requires two sections, one for each database. These are referred to as the “left” and the “right” database. |
| Schema Objects <SchemaObjects> |
Contains the type of database objects to compare such as tables, views, stored procedures. |
| Schema Options <SchemaOptions> |
Contains comparison options. |
| Command Line Settings <CommandLineSettings> |
Specifies other settings such as the file name of the synchronization script, synchronization log, error log, file encoding. |
| Schema Filter <SchemaFilterValueSet> |
Specifies schema filters that allow you to include or exclude specific database objects. |
A simple Xml configuration file has the following structure:
<?xml version="1.0" encoding="utf-8" ?>
<CommandLineParameters xmlns="http://www.xsqlsoftware.com/schemas/xSQLObjectCmdSchema.xsd">
<LeftDatabase>
<SqlServer>(local)</SqlServer>
<DatabaseName>DB_Prod</DatabaseName>
<TrustedConnection>true</TrustedConnection>
</LeftDatabase>
<RightDatabase>
<SqlServer>(local)</SqlServer>
<DatabaseName>DB_Staging</DatabaseName>
<TrustedConnection>true</TrustedConnection>
</RightDatabase>
<SchemaObjects>
<Object Type="DefaultObjects"></Object>
</SchemaObjects>
<SchemaOptions>
<Option>DefaultOptions</Option>
</SchemaOptions>
<CommandLineSettings>
<SchemaScriptFile>CmpScript.sql</SchemaScriptFile>
<SchemaLogFile>CmpLog.txt</SchemaLogFile>
<ErrorLogType>File</ErrorLogType>
<ErrorLogName>CmpErr.txt</ErrorLogName>
<CompareSchema Direction="LeftAsRight" Synchronize="false"></CompareSchema>
</CommandLineSettings>
</CommandLineParameters>
The <LeftDatabase> and <RightDatabase>
elements specify the database on the "left" and the "right" side of
the comparison respectively. In this example the databases
DB_Prod and DB_Staging are located on the
"(local)" SQL Server and the connection to SQL Server is
Trusted Connection.| <ErrorFile>: | Specifies the name of the file that will contain schema errors. |
| <SchemaScriptFile>: | The file name on which synchronization script will be saved. |
| <SchemaLogFile>: | The file name on which the synchronization logs will saved. |
| <CompareSchema>: | Indicates the direction of the comparison as LeftToRight
or RightToLeft. In a left-to-right comparison, the Command
Line makes the schema of the database specified by
<LeftDatabase> element the same as the schema of the
database specified by <RightDatabase> element. The attribute Synchronize determines whether the Command Line should stop with the generation of the schema differences script or whether it should execute the script to synchronize databases. A false value indicates that only the synchronization script should be generated. |
The following command invokes the Command Line with the Xml
configuration file (assuming that the file is named
simpleXml.xml)
xSQLObjectCmd simpleXml.xml
xSQL Object Command Line sample xml files are located in the \Samples\CommandLines\ObjectCmd subfolder under the main installation folder of xSQL Bundle.
<CommandLineParameters>
<LeftDatabase>
<SqlServer>
<DatabaseName>
<Username>
<Password>
<TrustedConnection>
<ConnectionTimeout>
<CommandTimeout>
<SnapshotFile>
<CreateSnapshot>
</LeftDatabase>
<RightDatabase>
<SqlServer>
<DatabaseName>
<Username>
<Password>
<TrustedConnection>
<ConnectionTimeout>
<CommandTimeout>
<SnapshotFile>
<CreateSnapshot>
</RightDatabase>
<SchemaFilterValueSets>
<FilterValueSet Name>
<Value MatchType>
</FilterValueSet>
</SchemaFilterValueSets>
<SchemaObjects>
<Object Type Action FilterValueSet FilterValidationType>
</SchemaObjects>
<SchemaOptions>
<Option>
</SchemaOptions>
<CommandLineSettings>
<LogFile>
<ErrorFile>
<SchemaScriptFile>
<SchemaLogFile>
<FileEncoding>
<CompareSchema Direction Synchronize>
</CommandLineSettings>
</ CommandLineParameters >
| Element | Description |
|---|---|
| CommandLineParameters | Root element. |
| LeftDatabase, RightDatabase | The elements that define the left and the right database. |
| SqlServer | The Sql Server that contains the database. |
| DatabaseName | The database name. |
| Username | The Sql Server login name. |
| Password | The Sql Server password. |
| TrustedConnection | The Sql server authentication type. true if the Windows authentication (trusted connection) should be used to connect to Sql Server; otherwise false. If not specified the default authentication method is Windows authentication. |
| ConnectionTimeout | The connection timeout in seconds, which is the amount of time that Command Line waits to establish a connection with the Sql server before generating an error. The default timeout is 60 seconds. |
| CommandTimeout | The command timeout in seconds, which is the amount of time that Command Line waits to execute a Sql statement before generating an error. The default timeout is 20 minutes. |
| SnapshotFile | Saves a snapshot of the database to the specified file. This requires that <CreateSnapshot> element to have the true. |
| CreateSnapshot | Forces Command Line to save a snapshot of the database before starting the comparison. The element <SnapshotFile> is required and must contain a valid file name. |
| SchemaFilterValueSets | Starts the schema filters section. |
| FilterValueSet | A schema filter element identified by the attribute Name. |
| Value | A schema filter criteria.
|
| SchemaObjects | Starts the section that defines the types of schema objects to include in or exclude from the comparison. |
| Object | A database object type to include or exclude from
the comparison. The object element contains the following
attributes:
AllObjects
DefaultObjects Table View StoredProcedure UserDefinedDataType UserDefinedFunction User Role PrimaryKey UniqueConstraint Index ForeignKey DefaultConstraint CheckConstraint Trigger Default Rule Permission ExtendedProperty FullTextCatalog Schema Certificate AsymmetricKey SymmetricKey PartitionFunction PartitionScheme Synonym ManagedAssembly UserDefinedAggregate UserDefinedType XMLSchemaCollection ServiceMessageType ServiceContract ServiceQueue ServiceRoute ServiceInstance RemoteServiceBinding ServicePriority DatabaseTrigger ServerTrigger
Include
Exclude>
AllCriteria AtLeastOneCriteria |
| SchemaOptions | Starts the section that defines the schema options. |
| Option | One of the following schema options:
DefaultOptions AlterAssemblyWithDropCreate BindDefaultsColumns BindDefaultsDataTypes BindRulesColumns BindRulesDataTypes CompareColumnsOrdinal CompareDefaultConstName CreateDefaultsFutureOnly CreateRulesFutureOnly GenerateTransaction IgnoreANSINulls IgnoreCharCase IgnoreCollation IgnoreQuotedIdentifier IgnoreSpaces IgnoreFunctionsComments IgnoreProcedureComments IgnoreTriggersComments IgnoreViewsComments IncludeEncryptedObjects IncludeIndexFillFactor IncludeIndexPadding IncludeIndexRecompute IncludeInvalidDependenies IncludeObjectsFileGroup OrderFunctionsByDependency OrderProceduresByDependency OrderViewsByDependency PerformFileGroupTranslation RaiseObjectsEvents CompareDataCompression CompareChangeTracking |
| CommandLineSettings | Contains additional settings used by the Command Line. |
| LogFile | Logs the schema comparison messages to the specified file. |
| ErrorLogType | Determines the type of logging of the schema comparison errors. This can be File or WindowsLog. |
| ErrorLogName | Logs the errors that might occur during the comparison or synchronization to the specified file or Windows log. |
| SchemaScriptFile | Saves the synchronization script to the specified file. |
| SchemaLogFile | Saves the synchronization logs to the specified file. |
| FileEncoding | Specifies the encoding of all output files. This element can have one of these values: Unicode, UTF7, UTF8, ASCII, ANSI. The default encoding is ANSI. |
| CompareSchema | Contains the following attributes:
|
The Command Line utility returns the following error
codes:
| Error Code | Description |
|---|---|
| 0 | No error |
| 1 | Invalid Command Line options |
| 2 | Invalid Xml file |
| 4 | The path of the output files is invalid |
| 8 | Failed to compare databases. |
| 16 | Failed to execute the synchronization script. |