Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions public/Publish-DbaDacPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/Publish-DbaDacPackage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Describe $CommandName -Tag UnitTests {
"Type",
"OutputPath",
"IncludeSqlCmdVars",
"CommandTimeout",
"DacOption",
"EnableException",
"DacFxPath"
Expand Down
Loading