Synchronizing database structure, saving SQL script problem

I have ran into a problem while synchronizing  database structure when the synchronization is cancelled for any reason (errors, foreign key constraints,....).

 

I am using the following PS Script:

 

$Conn1 = New-DatabaseConnection
-ServerInstance 'SQLSRV' -Database 'DB1' -Username 'Usr1' -Password 'Pwd1'

$Conn2 = New-DatabaseConnection
-ServerInstance 'SQLSRV' -Database 'DB2' -Username 'Usr2' -Password 'Pwd2'

$Options =
'DecryptPost2KEncryptedObjects, DisableAndReenableDdlTriggers,
ObjectExistenceChecks, -ForceColumnOrder,
IgnoreUsersPermissionsAndRoleMemberships, IgnoreUserProperties,
IgnoreWhiteSpace, UseCompatibilityLevel, IgnoreDatabaseAndServerName, IgnoreIdentitySeedAndIncrement,
IgnoreStatistics, IgnoreFillFactor, IgnoreFileGroups, IgnoreWithElementOrder'

$myFilterPath =
'D:\SYNC_SQL\SYNC_FILTER.scpf'

$syncResult =
Sync-DatabaseSchema -Source $Conn2 -Target $Conn1 -FilterPath $myFilterPath
-SQLCompareOptions $Options -AbortOnWarningLevel None -QueryBatchTimeout 300

$syncResult.UpdateSql | Out-File
-FilePath 'D:\SYNC_SQL\SYNC_SQL.sql'

 

When there is an error while synchronizing I dont know the object or table where the error occured.

So, I have an option to save the SQL synchronization script to file, this is where the problem appears, this script is only generated when the whole synchronization is succesfull.

If the synchronization is succesfull I don't need the script, I only need it when its NOT succesfull.

Answers

  • way0utwestway0utwest CO, USA Posts: 294 Rose Gold 1
    You might try this in SQL Compare and look for an issue with the objects.
  • dUrosdUros Posts: 20 Bronze 1
    Thank you for reply.

    I have install SQL Compare just on my PC on development network. On other servers on other networks I use SQL Change Automation, before I use SDK. It's not many problems but when appears SQL script is crucial. Problems appears mostly because of the data, which was different as data on my system. And not all servers are sync every time so SQL script are different on different servers (DB's).
Sign In or Register to comment.