Skip to content

Commit d0c3163

Browse files
Uninstall-DbaSqlWatch - Skip DACPAC unregister when no registration exists
Fixes test failures where Install-DbaSqlWatch's post-deployment script times out, leaving schema objects deployed but no DAC registration in msdb. The unconditional Unregister() call then threw 'DacInstance with the specified instance_id does not exist'. Now checks GetDatabases() before calling Unregister() so cleanup is safe regardless of whether the DACPAC registration completed. (do *SqlWatch*) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent b32aa4d commit d0c3163

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

public/Uninstall-DbaSqlWatch.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ Function Uninstall-DbaSqlWatch {
212212
Write-Message -Level Verbose -Message "Unpublishing SqlWatch DACPAC from $database on $server."
213213
$connectionString = $server.ConnectionContext.ConnectionString | Convert-ConnectionString
214214
$dacServices = New-Object Microsoft.SqlServer.Dac.DacServices $connectionString
215-
$dacServices.Unregister($Database)
215+
$registeredDatabases = $dacServices.GetDatabases()
216+
if ($Database -in $registeredDatabases) {
217+
$dacServices.Unregister($Database)
218+
} else {
219+
Write-Message -Level Verbose -Message "No DACPAC registration found for $database on $server, skipping unregister."
220+
}
216221
} catch {
217222
Stop-Function -Message "Failed to unpublish SqlWatch DACPAC from $database on $server." -ErrorRecord $_
218223
}

0 commit comments

Comments
 (0)