Skip to content

Commit

Permalink
Fix connection profile prompt for Create Function with SQL Binding (m…
Browse files Browse the repository at this point in the history
…icrosoft#19211)

* fix no connection profile and progress report

* show connection profile prompt if user exits object

* address comments
  • Loading branch information
VasuBhog authored Apr 27, 2022
1 parent 727f37d commit a3efb19
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions extensions/sql-bindings/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ export const userPasswordLater = localize('userPasswordLater', 'In order to user
export const openFile = localize('openFile', "Open File");
export const closeButton = localize('closeButton', "Close");
export function addSqlBinding(functionName: string): string { return localize('addSqlBinding', 'Adding SQL Binding to function "{0}"...'), functionName; }
export const connectionProgressTitle = localize('connectionProgressTitle', "Testing SQL Server connection...");
48 changes: 47 additions & 1 deletion extensions/sql-bindings/src/services/azureFunctionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
.withAdditionalProperties(propertyBag).send();


// Get connection string parameters and construct object name from prompt or connectionInfo given
let objectName: string | undefined;
const vscodeMssqlApi = await utils.getVscodeMssqlApi();
Expand All @@ -115,6 +114,53 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
telemetryStep = CreateAzureFunctionStep.launchFromCommandPalette;

// prompt user for connection profile to get connection info
while (true) {
connectionInfo = await vscodeMssqlApi.promptForConnection(true);
if (!connectionInfo) {
// User cancelled
return;
}
telemetryStep = 'getConnectionInfo';
let connectionURI: string = '';
try {
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: constants.connectionProgressTitle,
cancellable: false
}, async (_progress, _token) => {
// list databases based on connection profile selected
connectionURI = await vscodeMssqlApi.connect(connectionInfo!);
}
);
} catch (e) {
// mssql connection error will be shown to the user
// we will then prompt user to choose a connection profile again
continue;
}
// list databases based on connection profile selected
let listDatabases = await vscodeMssqlApi.listDatabases(connectionURI);
const selectedDatabase = (await vscode.window.showQuickPick(listDatabases, {
canPickMany: false,
title: constants.selectDatabase,
ignoreFocusOut: true
}));

if (!selectedDatabase) {
// User cancelled
// we will then prompt user to choose a connection profile again
continue;
}
connectionInfo.database = selectedDatabase;

// prompt user for object name to create function from
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding);
if (!objectName) {
// user cancelled
return;
}
break;
}
telemetryStep = CreateAzureFunctionStep.getConnectionProfile;
connectionInfo = await vscodeMssqlApi.promptForConnection(true);
if (!connectionInfo) {
Expand Down

0 comments on commit a3efb19

Please sign in to comment.