mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add SQL Binding Disconnected Scenario (#18440)
* disconnected scenario * match parameters in mssql
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { BindingType, IConnectionInfo } from 'vscode-mssql';
|
import { BindingType, ConnectionDetails, IConnectionInfo } from 'vscode-mssql';
|
||||||
import * as constants from '../common/constants';
|
import * as constants from '../common/constants';
|
||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||||
@@ -169,6 +169,7 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
|||||||
let connectionString: string = '';
|
let connectionString: string = '';
|
||||||
let includePassword: string | undefined;
|
let includePassword: string | undefined;
|
||||||
let connectionInfo: IConnectionInfo | undefined;
|
let connectionInfo: IConnectionInfo | undefined;
|
||||||
|
let connectionDetails: ConnectionDetails;
|
||||||
if (selectedConnectionStringMethod === constants.userConnectionString) {
|
if (selectedConnectionStringMethod === constants.userConnectionString) {
|
||||||
// User chooses to enter connection string manually
|
// User chooses to enter connection string manually
|
||||||
connectionString = await vscode.window.showInputBox(
|
connectionString = await vscode.window.showInputBox(
|
||||||
@@ -181,20 +182,12 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
|||||||
) ?? '';
|
) ?? '';
|
||||||
} else {
|
} else {
|
||||||
// Let user choose from existing connections to create connection string from
|
// Let user choose from existing connections to create connection string from
|
||||||
let connectionUri: string = '';
|
|
||||||
connectionInfo = await vscodeMssqlApi.promptForConnection(true);
|
connectionInfo = await vscodeMssqlApi.promptForConnection(true);
|
||||||
if (!connectionInfo) {
|
if (!connectionInfo) {
|
||||||
// User cancelled return to selectedConnectionStringMethod prompt
|
// User cancelled return to selectedConnectionStringMethod prompt
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
connectionDetails = { options: connectionInfo };
|
||||||
// TO DO: https://github.com/microsoft/azuredatastudio/issues/18012
|
|
||||||
connectionUri = await vscodeMssqlApi.connect(connectionInfo);
|
|
||||||
} catch (e) {
|
|
||||||
// display an mssql error due to connection request failing and go back to prompt for connection string methods
|
|
||||||
console.warn(e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// Prompt to include password in connection string if authentication type is SqlLogin and connection has password saved
|
// Prompt to include password in connection string if authentication type is SqlLogin and connection has password saved
|
||||||
if (connectionInfo.authenticationType === 'SqlLogin' && connectionInfo.password) {
|
if (connectionInfo.authenticationType === 'SqlLogin' && connectionInfo.password) {
|
||||||
@@ -205,12 +198,12 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined,
|
|||||||
});
|
});
|
||||||
if (includePassword === constants.yesString) {
|
if (includePassword === constants.yesString) {
|
||||||
// set connection string to include password
|
// set connection string to include password
|
||||||
connectionString = await vscodeMssqlApi.getConnectionString(connectionUri, true, false);
|
connectionString = await vscodeMssqlApi.getConnectionString(connectionDetails, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set connection string to not include the password if connection info does not include password, or user chooses to not include password, or authentication type is not sql login
|
// set connection string to not include the password if connection info does not include password, or user chooses to not include password, or authentication type is not sql login
|
||||||
if (includePassword !== constants.yesString) {
|
if (includePassword !== constants.yesString) {
|
||||||
connectionString = await vscodeMssqlApi.getConnectionString(connectionUri, false, false);
|
connectionString = await vscodeMssqlApi.getConnectionString(connectionDetails, false, false);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// failed to get connection string for selected connection and will go back to prompt for connection string methods
|
// failed to get connection string for selected connection and will go back to prompt for connection string methods
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ export class MockVscodeMssqlIExtension implements vscodeMssql.IExtension {
|
|||||||
getDatabaseNameFromTreeNode(_: vscodeMssql.ITreeNodeInfo): string {
|
getDatabaseNameFromTreeNode(_: vscodeMssql.ITreeNodeInfo): string {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
getConnectionString(__: string, ___?: boolean): Promise<string> {
|
getConnectionString(_: string | vscodeMssql.ConnectionDetails, ___?: boolean, _____?: boolean): Promise<string> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,13 +77,13 @@ declare module 'vscode-mssql' {
|
|||||||
getDatabaseNameFromTreeNode(node: ITreeNodeInfo): string;
|
getDatabaseNameFromTreeNode(node: ITreeNodeInfo): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the connection string for the provided connection Uri
|
* Get the connection string for the provided connection Uri or connection details.
|
||||||
* @param connectionUri The URI of the connection to get the connection string for.
|
* @param connectionUriOrDetails Either the connection Uri for the connection or the connection details for the connection is required.
|
||||||
* @param includePassword Whether the Password is included in the connection string. Default is false.
|
* @param includePassword (optional) if password should be included in connection string.
|
||||||
* @param includeApplicationName Whether the Application Name is included in the connection string. Default is true
|
* @param includeApplicationName (optional) if application name should be included in connection string.
|
||||||
* @returns connection string
|
* @returns connection string for the connection
|
||||||
*/
|
*/
|
||||||
getConnectionString(connectionUri: String, includePassword?: boolean, includeApplicationName?: boolean): Promise<string>;
|
getConnectionString(connectionUriOrDetails: string | ConnectionDetails, includePassword?: boolean, includeApplicationName?: boolean): Promise<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -633,4 +633,12 @@ declare module 'vscode-mssql' {
|
|||||||
*/
|
*/
|
||||||
azureFunctions: string[];
|
azureFunctions: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters to initialize a connection to a database
|
||||||
|
*/
|
||||||
|
export interface ConnectionDetails {
|
||||||
|
|
||||||
|
options: { [name: string]: any };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user