NoErrorHandling line option not being utilized
Stevie
Posts: 7 Bronze 1
in SQL Compare
I am having issues with passing the NoErrorHandling option to a SQL Compare (Version 14.2.9.15508 Professional) script I am writing in PowerShell. I have both the NoErrorHandling and NoTransactions options included, and while there is no rollback occurring after the error occurs, it does stop the process and prevent any additional deployment from occurring when synchronizing to the target database.
The specific error returned is
"Synonym '' refers to an invalid object.
System.Data.SqlClient"
The specific error returned is
"Synonym '' refers to an invalid object.
System.Data.SqlClient"
$MyParameters = @{
'Server1' = '';
'Database1' = '';
'Server2' = '';
'Database2' = '';
'options' = 'cs,nt,dp2k,nc,isoa,icn,iscn,idsn,ito,ie,ifg,if,inwn,infr,ipi,ip,irpt,iq,isb,ist,itst,iup,iu,iw,iweo,iwn,neh,ndl'; # Panther DBA Defaults
# cs - CaseSensitiveObjectDefinition
# nt - NoTransactions
# dp2k - DecryptPost2KEncryptedObjects
# nc - DoNotOutputCommentHeader
# isoa - IgnoreSchemaObjectAuthorization
# icn - IgnoreConstraintNames
# iscn - IgnoreSystemNamedConstraintNames
# idsn - IgnoreDatabaseAndServerName
# ito - IgnoreTriggerOrder
# ie - IgnoreExtendedProperties
# ifg - IgnoreFileGroups
# if - IgnoreFillFactor
# inwn - IgnoreNocheckAndWithNocheck
# infr - IgnoreNotForReplication
# ipi - IgnorePerformanceIndexes
# ip - IgnorePermissions
# irpt - IgnoreReplicationTriggers
# iq - IgnoreQuotedIdentifiersAndAnsiNullSettings
# isb - IgnoreSquareBrackets
# itst - IgnoretSQLt
# ist - IgnoreStatistics
# iup - IgnoreUserProperties
# iu - IgnoreUsersPermissionsAndRoleMemberships
# iw - IgnoreWhiteSpace
# iweo - IgnoreWithElementOrder
# iwn - IgnoreWithNoCheck
# neh - NoErrorHandling
# ndl - NoDeploymentLogging
'filter' = '';
'ScriptFile' = ""; #write to script file
'force' = $null; #force overwrite
'sync' = $null;
'Include' = 'Identical';
}
# Helper function - translate parameters to XML Format
Function SaveParamsAsSQLCompareXML([hashtable]$TheHashTableParameters,[string]$WhereToStoreIt)
{
$xmlDoc = [System.Xml.XmlDocument]'<?xml version="1.0"?>';
$commandline = $xmlDoc.AppendChild($xmlDoc.CreateElement('commandline'));
$TheHashTableParameters.GetEnumerator() | ForEach-Object {
$Element = $commandline.AppendChild($xmlDoc.CreateElement($_.Name));
if ($null -ne $_.Value) # if it is a switch with a parameter
{
$Element.AppendChild($xmlDoc.CreateTextNode($_.Value));
}
}
$xmlDoc.Save("$WhereToStoreIt"); #save it to the user temp area
}
SaveParamsAsSQLCompareXML $MyParameters "C:\Dev\Repos\DBATools\SQLCompareScripts\ParamFiles\Paramfile.xml";
.\SQLCompare.exe /Argfile:"C:\Dev\Repos\DBATools\SQLCompareScripts\ParamFiles\Paramfile.xml";
Tagged:
Best Answer
-
Tianjiao_Li Posts: 684 Rose Gold 5@Stevie
If you deploy using SQL Compare, the deployment is always stopped when an error is encountered. https://documentation.red-gate.com/sc/setting-up-the-comparison/setting-project-options
You could export the deployment script and run it in SSMS in your case.
Answers
If NoTransactions option isn't specified and the deployment script fails, the script is rolled back to the start of the failed transaction. If this option is specified, the script isn't rolled back as you've seen. This can be useful for detection of errors within a script.
From the error you got, it looks like there are issues with your Synonyms and you might need to make sure they are not referring to any invalid object.
Tianjiao Li | Redgate Software
Have you visited our Help Center?
Thank you for your response. However, the 'NoTransactions' option has been specified in the parameters. While the operation is not being rolled back, it is not continuing after the error in the script has been reached, which is what I understood the 'NoErrorHandling' option was meant to work around.
The script in question is comparing the schema at client instances which may very well have errors in their objects outside of DBA control.
TRY...CATCH
construct.