Utilizing the “no differences detected” return code in ApexSQL change management console applications

Applies to
ApexSQL Compare, ApexSQL Data Diff, ApexSQL Diff

Summary
This article explains the usage of the 102 – No differences detected return code when the compared data sources are equal.

Description

The 102 – No differences detected return code is returned in cases when the compared data sources are equal, instead of the normal 0 – Success return code. To use the new return code, a newly added CLI switch needs to be specified:

/rece [ /return_error_code_on_equal ]
Forces return code 102 – No differences detected, if the compared data sources are equal, otherwise the application returns return code 0 – Success

For example, let’s set up a PowerShell script to use ApexSQL Data Diff to compare two data sources.

First, let’s create a PowerShell script that will contain a saved project file with data sources and selected objects for the comparison, date stamped output summary, synchronization switch, and the /rece switch to return 102 – No differences detected if data sources are equal:

#define tool location, date stamp variable and tool’s parameters 
$datadiffLocation   = "ApexSQLDataDiff"
$dateStamp = (Get-Date -Format "_MMddyyyy_HHMMss") 
$datadiffParameters = "/pr:""MyProject.axdd"" /out:""Output_$dateStamp.txt"" /sync /v /f /rece" 

The following expression will be called to execute the tool and the return code variable is defined:

#compare data sources
(Invoke-Expression ("& `"" + $datadiffLocation +"`" " +$datadiffParameters))
$returnCode = $LASTEXITCODE 

Now, let’s define the potential outcomes as the next part in the PowerShell script.

If differences are detected, e.g. 0 – Success is returned or if there are no differences, e.g. 102 – No differences detected, it will be shown at the end of the output summary.

Also, if an error is encountered during the application execution, the corresponding return error code with description will be shown at the end of the created output summary:

#differences in compared data sources were detected
if($returnCode -eq 0)
{
"`r`n $LASTEXITCODE - Differences were successfully synchronized" >> "Output_$dateStamp.txt" 
}
else
{
    #no differences were detected
    if($returnCode -ne 102)
    {
"`r`n $LASTEXITCODE - No differences were detected" >> "Output_$dateStamp.txt" 
    }
    #an error occurred during the application execution
    else
    {
    "`r`n $LASTEXITCODE - An error occurred" >> "Output_$dateStamp.txt" 
    }
}   

Learn more about ApexSQL tools CLI return codes from here.

Running this job on two data sources that don’t have any differences will result in the follow message:

102 – No changes were detected. Job aborted

FAQs

Q: What will happen if the /rece switch is not specified and data sources are equal?

A: The application will provide the following message upon the finished comparison:

No differences were detected. There are no objects to synchronize

and the return code 0 will be shown.