From 5fdac2054dcfae2e5816aa26472a449b11c32c36 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:34:42 -0700 Subject: [PATCH] Add support for clearing pooled connections (#24325) --- extensions/mssql/package.json | 4 +++ extensions/mssql/package.nls.json | 3 +- extensions/mssql/src/connection/commands.ts | 19 +++++++++++ .../mssql/src/connection/connectionService.ts | 33 +++++++++++++++++++ extensions/mssql/src/connection/constants.ts | 6 ++++ extensions/mssql/src/contracts.ts | 5 +++ extensions/mssql/src/main.ts | 2 ++ extensions/mssql/src/sqlToolsServer.ts | 2 ++ 8 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 extensions/mssql/src/connection/commands.ts create mode 100644 extensions/mssql/src/connection/connectionService.ts create mode 100644 extensions/mssql/src/connection/constants.ts diff --git a/extensions/mssql/package.json b/extensions/mssql/package.json index 0c7800505a..5ba16ce607 100644 --- a/extensions/mssql/package.json +++ b/extensions/mssql/package.json @@ -157,6 +157,10 @@ "dark": "resources/dark/groupBySchemaDisabled_inverse.svg", "light": "resources/light/groupBySchemaDisabled.svg" } + }, + { + "command": "mssql.clearPooledConnections", + "title": "%mssql.connection.clearPooledConnections%" } ], "outputChannels": [ diff --git a/extensions/mssql/package.nls.json b/extensions/mssql/package.nls.json index 01c00ab891..268ccea7ef 100644 --- a/extensions/mssql/package.nls.json +++ b/extensions/mssql/package.nls.json @@ -174,9 +174,10 @@ "title.newTable": "New Table", "title.designTable": "Design", "title.changeNotebookConnection": "Change SQL Notebook Connection", + "mssql.connection.clearPooledConnections": "SQL Server: Clear Pooled Connections", "mssql.parallelMessageProcessing": "[Experimental] Whether the requests to the SQL Tools Service should be handled in parallel. This is introduced to discover the issues there might be when handling all requests in parallel. The default value is false. Azure Data Studio is required to be relaunched when the value is changed.", "mssql.enableSqlAuthenticationProvider": "Enables use of the Sql Authentication Provider for 'Active Directory Interactive' authentication mode when user selects 'AzureMFA' authentication. This enables Server-side resource endpoint integration when fetching access tokens. This option is only supported for 'MSAL' Azure Authentication Library. Azure Data Studio is required to be relaunched when the value is changed.", - "mssql.enableConnectionPooling": "Enables connection pooling on MSSQL connections to improve overall performance of Azure Data Studio connectivity. This setting is enabled by default. Azure Data Studio is required to be relaunched when the value is changed.", + "mssql.enableConnectionPooling": "Enables connection pooling on MSSQL connections to improve overall performance of Azure Data Studio connectivity. This setting is enabled by default. Azure Data Studio is required to be relaunched when the value is changed. To clear pooled connections, run the command: 'SQL Server: Clear Pooled Connections'", "mssql.tableDesigner.preloadDatabaseModel": "Whether to preload the database model when the database node in the object explorer is expanded. When enabled, the loading time of table designer can be reduced. Note: You might see higher than normal memory usage if you need to expand a lot of database nodes.", "mssql.tableDesigner.allowDisableAndReenableDdlTriggers": "Whether to allow table designer to disable and re-enable DDL triggers during publish", "mssql.objectExplorer.groupBySchema": "When enabled, the database objects in Object Explorer will be categorized by schema.", diff --git a/extensions/mssql/src/connection/commands.ts b/extensions/mssql/src/connection/commands.ts new file mode 100644 index 0000000000..af53b85783 --- /dev/null +++ b/extensions/mssql/src/connection/commands.ts @@ -0,0 +1,19 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { AppContext } from '../appContext'; +import * as vscode from 'vscode'; +import * as constants from './constants'; +import { ConnectionService } from './connectionService'; + +export function registerConnectionCommands(appContext: AppContext) { + appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.clearPooledConnections', async () => { + await getConnectionService(appContext).clearPooledConnections(); + })); +} + +function getConnectionService(appContext: AppContext): ConnectionService { + return appContext.getService(constants.ConnectionService); +} diff --git a/extensions/mssql/src/connection/connectionService.ts b/extensions/mssql/src/connection/connectionService.ts new file mode 100644 index 0000000000..dbcd24d930 --- /dev/null +++ b/extensions/mssql/src/connection/connectionService.ts @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as constants from './constants'; +import * as contracts from '../contracts'; + +import { BaseService, ISqlOpsFeature, SqlOpsDataClient } from 'dataprotocol-client'; +import { ClientCapabilities } from 'vscode-languageclient'; +import { AppContext } from '../appContext'; + +export class ConnectionService extends BaseService { + public static asFeature(context: AppContext): ISqlOpsFeature { + return class extends ConnectionService { + constructor(client: SqlOpsDataClient) { + super(context, client); + } + + fillClientCapabilities(_: ClientCapabilities): void { } + initialize(): void { } + }; + } + + private constructor(context: AppContext, client: SqlOpsDataClient) { + super(client); + context.registerService(constants.ConnectionService, this); + } + + async clearPooledConnections(): Promise { + return this.runWithErrorHandling(contracts.ClearPooledConnectionsRequest.type, {}); + } +} diff --git a/extensions/mssql/src/connection/constants.ts b/extensions/mssql/src/connection/constants.ts new file mode 100644 index 0000000000..2320209907 --- /dev/null +++ b/extensions/mssql/src/connection/constants.ts @@ -0,0 +1,6 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +export const ConnectionService = 'ConnectionService'; diff --git a/extensions/mssql/src/contracts.ts b/extensions/mssql/src/contracts.ts index f8774bbf7f..c51c655426 100644 --- a/extensions/mssql/src/contracts.ts +++ b/extensions/mssql/src/contracts.ts @@ -1733,6 +1733,11 @@ export namespace EncryptionKeysChangedNotification { export const type = new NotificationType('connection/encryptionKeysChanged'); } +// ------------------------------- < Clear Pooled Connections Request > --------------------------------------- + +export namespace ClearPooledConnectionsRequest { + export const type = new RequestType('connection/clearpooledconnections'); +} // ------------------------------- < Query Store > ------------------------------------ //#region Query Store diff --git a/extensions/mssql/src/main.ts b/extensions/mssql/src/main.ts index ea105a4ab2..0101fe7936 100644 --- a/extensions/mssql/src/main.ts +++ b/extensions/mssql/src/main.ts @@ -27,6 +27,7 @@ import { registerTableDesignerCommands } from './tableDesigner/tableDesigner'; import { registerObjectManagementCommands } from './objectManagement/commands'; import { TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry'; import { noConvertResult, noDocumentFound, unsupportedPlatform } from './localizedConstants'; +import { registerConnectionCommands } from './connection/commands'; const localize = nls.loadMessageBundle(); @@ -156,6 +157,7 @@ export async function activate(context: vscode.ExtensionContext): Promise