diff --git a/public/Publish-DbaDacPackage.ps1 b/public/Publish-DbaDacPackage.ps1 index f0fa1ccdc1c..a861f75d1b0 100644 --- a/public/Publish-DbaDacPackage.ps1 +++ b/public/Publish-DbaDacPackage.ps1 @@ -54,6 +54,10 @@ function Publish-DbaDacPackage { Enables replacement of SqlCmd variables in the publish profile with their actual values during deployment. Use this when your deployment scripts or publish profile contain variables like $(Environment) or $(ServerName) that need to be substituted with environment-specific values. + .PARAMETER CommandTimeout + Specifies the execution timeout in seconds for SQL commands during deployment. Set to 0 for no timeout. + Defaults to 0. Use this for DACPAC packages with long-running pre/post-deployment scripts that may exceed the default 30-second SqlClient command timeout. + .PARAMETER WhatIf Shows what would happen if the command were to run. No actions are actually performed. @@ -149,7 +153,7 @@ function Publish-DbaDacPackage { [PSCredential]$SqlCredential, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string]$Path, - [Parameter(ParameterSetName = 'Xml')] + [Parameter(ParameterSetName = "Xml")] [string]$PublishXml, [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string[]]$Database, @@ -160,7 +164,8 @@ function Publish-DbaDacPackage { [string]$Type = 'Dacpac', [string]$OutputPath = (Get-DbatoolsConfigValue -FullName 'Path.DbatoolsExport'), [switch]$IncludeSqlCmdVars, - [Parameter(ParameterSetName = 'Obj')] + [int]$CommandTimeout = 0, + [Parameter(ParameterSetName = "Obj")] [Alias("Option")] [object]$DacOption, [switch]$EnableException, @@ -322,16 +327,22 @@ function Publish-DbaDacPackage { $options.MasterDbScriptPath = Join-Path $OutputPath "$cleaninstance-$dbName`_Master.DeployScript_$timeStamp.sql" } } - if ($connString -notmatch 'Database=') { + if ($connString -notmatch "Database=") { $connString = "$connString;Database=$dbName" } - #Create services object try { $dacServices = New-Object Microsoft.SqlServer.Dac.DacServices $connString } catch { Stop-Function -Message "Error occurred while establishing connection to $instance" -Category ConnectionError -ErrorRecord $_ -Target $server -Continue } + if (Test-Bound -ParameterName CommandTimeout) { + if ($null -ne $dacServices.GetType().GetProperty("CommandTimeout")) { + $dacServices.CommandTimeout = $CommandTimeout + } else { + Write-Message -Level Warning -Message "CommandTimeout is not supported by this version of DacFx. Upgrade SSDT or DacFx to use this parameter." + } + } try { $null = $output = Register-ObjectEvent -InputObject $dacServices -EventName "Message" -SourceIdentifier "msg" -ErrorAction SilentlyContinue -Action { diff --git a/tests/Publish-DbaDacPackage.Tests.ps1 b/tests/Publish-DbaDacPackage.Tests.ps1 index 20d39c662ac..149907dccf7 100644 --- a/tests/Publish-DbaDacPackage.Tests.ps1 +++ b/tests/Publish-DbaDacPackage.Tests.ps1 @@ -22,6 +22,7 @@ Describe $CommandName -Tag UnitTests { "Type", "OutputPath", "IncludeSqlCmdVars", + "CommandTimeout", "DacOption", "EnableException", "DacFxPath"