Skip to content

Commit 3dc7060

Browse files
New-DbaConnectionString - Fix issues with parameter EncryptConnection (#9724)
1 parent 156fdb9 commit 3dc7060

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

public/New-DbaConnectionString.ps1

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ function New-DbaConnectionString {
196196
[string]$ClientName = "custom connection",
197197
[int]$ConnectTimeout,
198198
[string]$Database,
199-
[ValidateSet('Mandatory', 'Optional', 'Strict', 'True', 'False')]
200199
[switch]$EncryptConnection = (Get-DbatoolsConfigValue -FullName 'sql.connection.encrypt'),
201200
[string]$FailoverPartner,
202201
[switch]$IsActiveDirectoryUniversalAuth,
@@ -271,9 +270,6 @@ function New-DbaConnectionString {
271270
if (Test-Bound -Not -ParameterName 'ConnectTimeout') {
272271
$ConnectTimeout = ([Dataplat.Dbatools.Connection.ConnectionHost]::SqlConnectionTimeout)
273272
}
274-
if (Test-Bound -Not -ParameterName 'EncryptConnection') {
275-
$EncryptConnection = (Get-DbatoolsConfigValue -FullName 'sql.connection.encrypt')
276-
}
277273
if (Test-Bound -Not -ParameterName 'NetworkProtocol') {
278274
$np = (Get-DbatoolsConfigValue -FullName 'sql.connection.protocol')
279275
if ($np) {
@@ -320,7 +316,8 @@ function New-DbaConnectionString {
320316
if ($Database) { $connStringBuilder['Initial Catalog'] = $Database }
321317
# https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlconnectionstringbuilder.encrypt?view=sqlclient-dotnet-standard-5.0
322318
if ($instance -notmatch "localdb") {
323-
if ($EncryptConnection) { $connStringBuilder['Encrypt'] = $EncryptConnection }
319+
if ($EncryptConnection) { $connStringBuilder['Encrypt'] = 'Mandatory' }
320+
if (-not $EncryptConnection -and (Test-Bound -ParameterName 'EncryptConnection')) { $connStringBuilder['Encrypt'] = 'False' }
324321
} else {
325322
Write-Message -Level Verbose -Message "localdb detected, skipping unsupported keyword 'Encryption'"
326323
}

0 commit comments

Comments
 (0)