@@ -82,7 +82,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
82
82
83
83
private async loadRecentConnections ( ) {
84
84
const recentConnections = this . _mainController . connectionManager . connectionStore . loadAllConnections ( true ) . map ( c => c . connectionCreds ) ;
85
- const dialogConnections = [ ] ;
85
+ const dialogConnections : IConnectionDialogProfile [ ] = [ ] ;
86
86
for ( let i = 0 ; i < recentConnections . length ; i ++ ) {
87
87
dialogConnections . push ( await this . initializeConnectionForDialog ( recentConnections [ i ] ) ) ;
88
88
}
@@ -106,25 +106,38 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
106
106
this . state . connectionProfile = emptyConnection ;
107
107
}
108
108
109
- private async initializeConnectionForDialog ( connection : IConnectionInfo ) {
109
+ private async initializeConnectionForDialog ( connection : IConnectionInfo ) : Promise < IConnectionDialogProfile > {
110
110
// Load the password if it's saved
111
111
const isConnectionStringConnection = connection . connectionString !== undefined && connection . connectionString !== '' ;
112
- const password = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
113
112
if ( ! isConnectionStringConnection ) {
113
+ const password = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
114
114
connection . password = password ;
115
115
} else {
116
- connection . connectionString = '' ;
117
- // extract password from connection string it starts after 'Password=' and ends before ';'
118
- const passwordIndex = password . indexOf ( 'Password=' ) === - 1 ? password . indexOf ( 'password=' ) : password . indexOf ( 'Password=' ) ;
119
- if ( passwordIndex !== - 1 ) {
120
- const passwordStart = passwordIndex + 'Password=' . length ;
121
- const passwordEnd = password . indexOf ( ';' , passwordStart ) ;
122
- if ( passwordEnd !== - 1 ) {
123
- connection . password = password . substring ( passwordStart , passwordEnd ) ;
116
+ // If the connection is a connection string connection with SQL Auth:
117
+ // * the full connection string is stored as the "password" in the credential store
118
+ // * we need to extract the password from the connection string
119
+ // If the connection is a connection string connection with a different auth type, then there's nothing in the credential store.
120
+
121
+ const connectionString = await this . _mainController . connectionManager . connectionStore . lookupPassword ( connection , isConnectionStringConnection ) ;
122
+
123
+ if ( connectionString ) {
124
+ const passwordIndex = connectionString . indexOf ( 'Password=' ) === - 1 ? connectionString . indexOf ( 'password=' ) : connectionString . indexOf ( 'Password=' ) ;
125
+
126
+ if ( passwordIndex !== - 1 ) {
127
+ // extract password from connection string; found between 'Password=' and the next ';'
128
+ const passwordStart = passwordIndex + 'Password=' . length ;
129
+ const passwordEnd = connectionString . indexOf ( ';' , passwordStart ) ;
130
+ if ( passwordEnd !== - 1 ) {
131
+ connection . password = connectionString . substring ( passwordStart , passwordEnd ) ;
132
+ }
133
+
134
+ // clear the connection string from the IConnectionDialogProfile so that the ugly connection string key
135
+ // that's used to look up the actual connection string (with password) isn't displayed
136
+ connection . connectionString = '' ;
124
137
}
125
138
}
126
-
127
139
}
140
+
128
141
const dialogConnection = connection as IConnectionDialogProfile ;
129
142
// Set the profile name
130
143
dialogConnection . profileName = dialogConnection . profileName ?? getConnectionDisplayName ( connection ) ;
0 commit comments