You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: public/Connect-DbaInstance.ps1
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -673,6 +673,22 @@ function Connect-DbaInstance {
673
673
$sqlConnectionInfo.Password=$csb.Password
674
674
$null=$csb.Remove('Password')
675
675
}
676
+
# look for 'Initial Catalog' and 'Database' in the connection string
677
+
$specifiedDatabase=$csb['Database']
678
+
if ($specifiedDatabase-eq'') {
679
+
$specifiedDatabase=$csb['Initial Catalog']
680
+
}
681
+
if ($Database-and$Database-ne$specifiedDatabase) {
682
+
Write-Message-Level Debug -Message "Database specified in connection string '$specifiedDatabase' does not match Database parameter '$Database'. Database parameter will be used."
683
+
# clear both, in order to not be overridden later by setting all AddtionalParameters
684
+
if ($csb.ShouldSerialize('Database')) {
685
+
$csb.Remove('Database')
686
+
}
687
+
if ($csb.ShouldSerialize('Initial Catalog')) {
688
+
$csb.Remove('Initial Catalog')
689
+
}
690
+
$sqlConnectionInfo.DatabaseName=$Database
691
+
}
676
692
677
693
# Add all remaining parts of the connection string as additional parameters.
0 commit comments