Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection string related issues #17737

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
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