Skip to content

Commit 3fca4ce

Browse files
Copy-DbaDatabase - Fix enabling broker on prefixed databases (#9714)
Co-authored-by: Chrissy LeMaire <[email protected]>
1 parent 72b3ed5 commit 3fca4ce

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

public/Copy-DbaDatabase.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,9 +1397,17 @@ function Copy-DbaDatabase {
13971397
$NewDatabase.Alter()
13981398
Write-Message -Level Verbose -Message "Successfully updated BrokerEnabled to $sourceDbBrokerEnabled for $destinationDbName on $destinstance."
13991399
} catch {
1400-
Write-Message -Level Warning -Message "Failed to update BrokerEnabled to $sourceDbBrokerEnabled for $destinationDbName on $destinstance."
1401-
1402-
$propfailures += "Message broker"
1400+
try {
1401+
Write-Message -Level Verbose -Message "Updating BrokerEnabled to $sourceDbBrokerEnabled for $destinationDbName on $destinstance failed so we try to regenerate the broker identifier."
1402+
$quotedDatabaseName = $destserver.Query("SELECT QUOTENAME('$($destinationDbName.Replace("'", "''"))') AS quotename").quotename
1403+
$null = $destserver.Query("ALTER DATABASE $quotedDatabaseName SET NEW_BROKER WITH ROLLBACK IMMEDIATE")
1404+
$NewDatabase.BrokerEnabled = $sourceDbBrokerEnabled
1405+
$null = $NewDatabase.Alter()
1406+
Write-Message -Level Verbose -Message "Successfully updated BrokerEnabled to $sourceDbBrokerEnabled for $destinationDbName on $destinstance."
1407+
} catch {
1408+
Write-Message -Level Warning -Message "Failed to update BrokerEnabled to $sourceDbBrokerEnabled for $destinationDbName on $destinstance."
1409+
$propfailures += "Message broker"
1410+
}
14031411
}
14041412
}
14051413
}

0 commit comments

Comments
 (0)