Fix connection profile prompt for Create Function with SQL Binding (#19211)

* fix no connection profile and progress report

* show connection profile prompt if user exits object

* address comments
This commit is contained in:
Vasu Bhog
2022-04-27 15:14:39 -07:00
committed by GitHub
parent 727f37d6a5
commit a3efb193e0
2 changed files with 48 additions and 1 deletions

View File

@@ -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...");

View File

@@ -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();
@@ -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) {