Skip to content

Commit

Permalink
Fix connection string related issues (#17737)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra committed Jul 12, 2023
1 parent 54d66bb commit 78b5e75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
16 changes: 13 additions & 3 deletions src/models/connectionCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,17 @@ export class ConnectionCredentials implements IConnectionInfo {
}
}
},
default: defaultProfileValues ? await connectionStore.lookupPassword(defaultProfileValues) : undefined
default: async (value) => {
if (value.connectionString) {
if ((value as IConnectionProfile).savePassword) {
// look up connection string
let connectionString = await connectionStore.lookupPassword(value, true);
value.connectionString = connectionString;
}
} else {
return await connectionStore.lookupPassword(value);
}
}
}
];
return questions;
Expand Down Expand Up @@ -298,8 +308,8 @@ export class ConnectionCredentials implements IConnectionInfo {

public static isPasswordBasedConnectionString(connectionString: string): boolean {
const connString = connectionString.toLowerCase();
return connString.includes('user') &&
connString.includes('password') &&
return (connString.includes('user') || connString.includes('uid') || connString.includes('userid')) &&
(connString.includes('password') || connString.includes('pwd')) &&
!connString.includes('Integrated Security');
}

Expand Down
25 changes: 7 additions & 18 deletions src/models/connectionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { IConnectionInfo, IServerInfo } from 'vscode-mssql';
import * as Constants from '../constants/constants';
import * as LocalizedConstants from '../constants/localizedConstants';
import { EncryptOptions, IConnectionProfile } from '../models/interfaces';
import { EncryptOptions } from '../models/interfaces';
import * as Interfaces from './interfaces';
import * as Utils from './utils';

Expand Down Expand Up @@ -137,25 +137,14 @@ export function getPicklistDetails(connCreds: IConnectionInfo): string {
*/
export function getConnectionDisplayString(creds: IConnectionInfo): string {
// Update the connection text
let text: string;
if (creds.connectionString) {
// If a connection string is present, try to display the profile name
if ((<IConnectionProfile>creds).profileName) {
text = (<IConnectionProfile>creds).profileName;
text = appendIfNotEmpty(text, creds.connectionString);
} else {
text = creds.connectionString;
}
let text: string = creds.server;
if (creds.database !== '') {
text = appendIfNotEmpty(text, creds.database);
} else {
text = creds.server;
if (creds.database !== '') {
text = appendIfNotEmpty(text, creds.database);
} else {
text = appendIfNotEmpty(text, LocalizedConstants.defaultDatabaseLabel);
}
let user: string = getUserNameOrDomainLogin(creds);
text = appendIfNotEmpty(text, user);
text = appendIfNotEmpty(text, LocalizedConstants.defaultDatabaseLabel);
}
let user: string = getUserNameOrDomainLogin(creds);
text = appendIfNotEmpty(text, user);

// Limit the maximum length of displayed text
if (text.length > Constants.maxDisplayedStatusTextLength) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ConnectionStore {
* @returns {string} formatted string with server, DB and username
*/
public static formatCredentialId(server: string, database?: string, user?: string, itemType?: string, isConnectionString?: boolean): string {
if (Utils.isEmpty(server)) {
if (Utils.isEmpty(server) && !isConnectionString) {
throw new ValidationException('Missing Server Name, which is required');
}
let cred: string[] = [ConnectionStore.CRED_PREFIX];
Expand Down Expand Up @@ -116,7 +116,7 @@ export class ConnectionStore {
* @returns {Promise<IConnectionCredentialsQuickPickItem[]>}
*/
public getPickListItems(): IConnectionCredentialsQuickPickItem[] {
let pickListItems: IConnectionCredentialsQuickPickItem[] = this.loadAllConnections(true);
let pickListItems: IConnectionCredentialsQuickPickItem[] = this.loadAllConnections(false);
pickListItems.push(<IConnectionCredentialsQuickPickItem>{
label: `$(add) ${LocalizedConstants.CreateProfileFromConnectionsListLabel}`,
connectionCreds: undefined,
Expand Down

0 comments on commit 78b5e75

Please sign in to comment.