Skip to content

Commit 242f1bf

Browse files
Publish-DbaDacPackage - Add CommandTimeout parameter to fix deployment timeouts
Adds a -CommandTimeout parameter (default 0 = no timeout) that is injected into the DacServices connection string. This fixes failures where complex post-deployment scripts (e.g. SqlWatch MERGE statements) exceed SqlClient's default 30-second command timeout. (do Publish-DbaDacPackage) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent b32aa4d commit 242f1bf

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

public/Publish-DbaDacPackage.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function Publish-DbaDacPackage {
5454
Enables replacement of SqlCmd variables in the publish profile with their actual values during deployment.
5555
Use this when your deployment scripts or publish profile contain variables like $(Environment) or $(ServerName) that need to be substituted with environment-specific values.
5656
57+
.PARAMETER CommandTimeout
58+
Specifies the execution timeout in seconds for SQL commands during deployment. Set to 0 for no timeout.
59+
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.
60+
5761
.PARAMETER WhatIf
5862
Shows what would happen if the command were to run. No actions are actually performed.
5963
@@ -149,7 +153,7 @@ function Publish-DbaDacPackage {
149153
[PSCredential]$SqlCredential,
150154
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
151155
[string]$Path,
152-
[Parameter(ParameterSetName = 'Xml')]
156+
[Parameter(ParameterSetName = "Xml")]
153157
[string]$PublishXml,
154158
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
155159
[string[]]$Database,
@@ -160,7 +164,8 @@ function Publish-DbaDacPackage {
160164
[string]$Type = 'Dacpac',
161165
[string]$OutputPath = (Get-DbatoolsConfigValue -FullName 'Path.DbatoolsExport'),
162166
[switch]$IncludeSqlCmdVars,
163-
[Parameter(ParameterSetName = 'Obj')]
167+
[int]$CommandTimeout = 0,
168+
[Parameter(ParameterSetName = "Obj")]
164169
[Alias("Option")]
165170
[object]$DacOption,
166171
[switch]$EnableException,
@@ -322,9 +327,12 @@ function Publish-DbaDacPackage {
322327
$options.MasterDbScriptPath = Join-Path $OutputPath "$cleaninstance-$dbName`_Master.DeployScript_$timeStamp.sql"
323328
}
324329
}
325-
if ($connString -notmatch 'Database=') {
330+
if ($connString -notmatch "Database=") {
326331
$connString = "$connString;Database=$dbName"
327332
}
333+
if ($connString -notmatch "CommandTimeout=") {
334+
$connString = "$connString;CommandTimeout=$CommandTimeout"
335+
}
328336

329337
#Create services object
330338
try {

tests/Publish-DbaDacPackage.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Describe $CommandName -Tag UnitTests {
2222
"Type",
2323
"OutputPath",
2424
"IncludeSqlCmdVars",
25+
"CommandTimeout",
2526
"DacOption",
2627
"EnableException",
2728
"DacFxPath"

0 commit comments

Comments
 (0)