diff --git a/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts b/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts index 66f1106672..b729a1cc79 100644 --- a/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts +++ b/extensions/sql-database-projects/src/dialogs/publishDatabaseQuickpick.ts @@ -69,14 +69,26 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise< // so exit the flow. return; } + quickPick.hide(); // Hide the quickpick immediately so it isn't showing while the API loads // 2. Select connection - const api = await getVscodeMssqlApi(); - const connectionProfile = await api.promptForConnection(); - if (!connectionProfile) { - return; + const vscodeMssqlApi = await getVscodeMssqlApi(); + let dbs: string[] | undefined = undefined; + while (!dbs) { + const connectionProfile = await vscodeMssqlApi.promptForConnection(true); + if (!connectionProfile) { + return; + } + // Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't + try { + dbs = await vscodeMssqlApi.listDatabases(connectionProfile); + } catch (err) { + // no-op, the mssql extension handles showing the error to the user. We'll just go + // back and prompt the user for a connection again + } } - const dbs = ['db1', 'db2']; + + // 3. Select database const dbQuickpicks = dbs.map(db => { return { label: db, @@ -93,10 +105,9 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise< } dbQuickpicks.push({ label: constants.createNew, dbName: '', isCreateNew: true }); - // 3. Select database - // TODO@chgagnon: Hook up to MSSQL - let databaseName = ''; - while (databaseName === '') { + + let databaseName: string | undefined = undefined; + while (!databaseName) { const selectedDatabase = await vscode.window.showQuickPick( dbQuickpicks, { title: constants.selectDatabase, ignoreFocusOut: true }); @@ -117,7 +128,6 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise< } } - // 4. Modify sqlcmd vars // If a publish profile is provided then the values from there will overwrite the ones in the // project file (if they exist) diff --git a/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts b/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts index 448b768086..94ec4fe523 100644 --- a/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts +++ b/extensions/sql-database-projects/src/typings/vscode-mssql.d.ts @@ -28,8 +28,16 @@ declare module 'vscode-mssql' { /** * Prompts the user to select an existing connection or create a new one, and then returns the result + * @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false) */ - promptForConnection(): Promise + promptForConnection(ignoreFocusOut?: boolean): Promise; + + /** + * Lists the databases for a given connection. An error is thrown and displayed to the user if an + * error occurs while connecting + * @param connection The connection to list the databases for + */ + listDatabases(connection: IConnectionInfo): Promise; } /**