Skip to content

Commit e4571e9

Browse files
Connect-DbaInstance - Trust server certificate for localhost DAC connections
When using DedicatedAdminConnection with a localhost instance, the server name is changed to 'ADMIN:localhost' to avoid multi-IP resolution issues (#10151). However, if TLS encryption is enabled, the SQL Server certificate (issued to the FQDN, e.g., 'r9d9.pup.local') doesn't match 'localhost', causing the error 'The target principal name is incorrect' (#10254). Automatically set TrustServerCertificate=true when connecting via DAC to localhost, since the hostname mismatch is expected and acceptable in this context. Applies to both the String input path and the Server/copyContext path. (do *Connect*) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent 2323952 commit e4571e9

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

public/Connect-DbaInstance.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ function Connect-DbaInstance {
648648
$serverName = "ADMIN:localhost"
649649
}
650650
Write-Message -Level Debug -Message "IsLocalHost is true, using '$serverName' for DAC to avoid multi-IP resolution."
651+
# Trust the server certificate because 'localhost' may not match the certificate CN (e.g., FQDN), issue #10254
652+
$TrustServerCertificate = $true
651653
} else {
652654
$serverName = "ADMIN:$serverName"
653655
}
@@ -721,6 +723,8 @@ function Connect-DbaInstance {
721723
} else {
722724
$connContext.ServerInstance = "ADMIN:localhost"
723725
}
726+
# Trust the server certificate because 'localhost' may not match the certificate CN (e.g., FQDN), issue #10254
727+
$connContext.TrustServerCertificate = $true
724728
} else {
725729
$connContext.ServerInstance = 'ADMIN:' + $connContext.ServerInstance
726730
}

0 commit comments

Comments
 (0)