diff --git a/extensions/sql-database-projects/src/dialogs/createProjectFromDatabaseQuickpick.ts b/extensions/sql-database-projects/src/dialogs/createProjectFromDatabaseQuickpick.ts index 81d723f4a8..02c7c5f950 100644 --- a/extensions/sql-database-projects/src/dialogs/createProjectFromDatabaseQuickpick.ts +++ b/extensions/sql-database-projects/src/dialogs/createProjectFromDatabaseQuickpick.ts @@ -6,7 +6,7 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as constants from '../common/constants'; -import { exists, getVscodeMssqlApi, isValidBasenameErrorMessage, sanitizeStringForFilename } from '../common/utils'; +import { exists, getVscodeMssqlApi, isValidBasenameErrorMessage, sanitizeStringForFilename, getErrorMessage } from '../common/utils'; import { IConnectionInfo } from 'vscode-mssql'; import { defaultProjectNameFromDb, defaultProjectSaveLocation } from '../tools/newProjectTool'; import { ImportDataModel } from '../models/api/import'; @@ -30,21 +30,28 @@ export async function createNewProjectFromDatabaseWithQuickpick(connectionInfo?: } let connectionUri: string = ''; let dbs: string[] | undefined = undefined; + + let isValidProfile = connectionProfile?.server !== undefined; // undefined when createProjectFromDatabase is launched without context (via command palette) + while (!dbs) { // Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't - try { - connectionUri = await vscodeMssqlApi.connect(connectionProfile); - dbs = (await vscodeMssqlApi.listDatabases(connectionUri)) - .filter(db => !constants.systemDbs.includes(db)); // Filter out system dbs - } catch (err) { - // The mssql extension handles showing the error to the user. Prompt the user - // for a new connection and then go and try getting the DBs again + if (isValidProfile) { + try { + connectionUri = await vscodeMssqlApi.connect(connectionProfile); + dbs = (await vscodeMssqlApi.listDatabases(connectionUri)) + .filter(db => !constants.systemDbs.includes(db)); // Filter out system dbs + } catch (err) { + // Prompt the user for a new connection and then go and try getting the DBs again + isValidProfile = false; + console.error(getErrorMessage(err)); + } + } else { connectionProfile = await vscodeMssqlApi.promptForConnection(true); if (!connectionProfile) { - // User cancelled - return undefined; + return undefined; // cancelled by user + } else { + isValidProfile = true; } - } }