Skip to content

Commit 8a6877d

Browse files
Publish-DbaDacPackage - Fix CommandTimeout: check property exists via reflection before setting
CommandTimeout was added to DacServices in newer DacFx versions (16.x+). Older DacFx (e.g. SQL Server 2019 ships 15.x) does not have this property, causing 'The property CommandTimeout cannot be found on this object'. Use reflection to check property exists before setting. Emit a warning when the installed DacFx version does not support CommandTimeout. Also separate the property set from the connection try/catch to avoid a misleading 'Error occurred while establishing connection' warning message. Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent 73177d7 commit 8a6877d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

public/Publish-DbaDacPackage.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,16 @@ function Publish-DbaDacPackage {
333333
#Create services object
334334
try {
335335
$dacServices = New-Object Microsoft.SqlServer.Dac.DacServices $connString
336-
$dacServices.CommandTimeout = $CommandTimeout
337336
} catch {
338337
Stop-Function -Message "Error occurred while establishing connection to $instance" -Category ConnectionError -ErrorRecord $_ -Target $server -Continue
339338
}
339+
if (Test-Bound -ParameterName CommandTimeout) {
340+
if ($null -ne $dacServices.GetType().GetProperty("CommandTimeout")) {
341+
$dacServices.CommandTimeout = $CommandTimeout
342+
} else {
343+
Write-Message -Level Warning -Message "CommandTimeout is not supported by this version of DacFx. Upgrade SSDT or DacFx to use this parameter."
344+
}
345+
}
340346

341347
try {
342348
$null = $output = Register-ObjectEvent -InputObject $dacServices -EventName "Message" -SourceIdentifier "msg" -ErrorAction SilentlyContinue -Action {

0 commit comments

Comments
 (0)