Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clearing pooled connections + enable pooling by default #17786

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"outFiles": [
"${workspaceRoot}/out/src/**/*.js"
],
"preLaunchTask": "build",
// "preLaunchTask": "build",
"env": {
// Uncomment this to use a specified version of STS, see
// https://github.com/microsoft/vscode-mssql/blob/main/DEVELOPMENT.md#using-mssql_sqltoolsservice-environment-variable
Expand Down
5 changes: 4 additions & 1 deletion localization/xliff/enu/localizedPackage.json.enu.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<trans-unit id="mssql.manageProfiles">
<source xml:lang="en">Manage Connection Profiles</source>
</trans-unit>
<trans-unit id="mssql.clearPooledConnections">
<source xml:lang="en">Clear Pooled Connections</source>
</trans-unit>
<trans-unit id="mssql.chooseDatabase">
<source xml:lang="en">Use Database</source>
</trans-unit>
Expand Down Expand Up @@ -219,7 +222,7 @@
<source xml:lang="en">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. Please restart Visual Studio Code after changing this option.</source>
</trans-unit>
<trans-unit id="mssql.enableConnectionPooling">
<source xml:lang="en">Enables connection pooling to improve overall connectivity performance. This setting is disabled by default. Visual Studio Code is required to be relaunched when the value is changed.</source>
<source xml:lang="en">Enables connection pooling to improve overall connectivity performance. This setting is enabled by default. Visual Studio Code is required to be relaunched when the value is changed. To clear pooled connections, run the command: 'MS SQL: Clear Pooled Connections'</source>
</trans-unit>
<trans-unit id="mssql.shortcuts">
<source xml:lang="en">Shortcuts related to the results window</source>
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@
"title": "%mssql.manageProfiles%",
"category": "MS SQL"
},
{
"command": "mssql.clearPooledConnections",
"title": "%mssql.clearPooledConnections%",
"category": "MS SQL"
},
{
"command": "mssql.chooseDatabase",
"title": "%mssql.chooseDatabase%",
Expand Down Expand Up @@ -909,7 +914,7 @@
"mssql.enableConnectionPooling": {
"type": "boolean",
"description": "%mssql.enableConnectionPooling%",
"default": false
"default": true
},
"mssql.format.alignColumnDefinitionsInColumns": {
"type": "boolean",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"mssql.connect":"Connect",
"mssql.disconnect":"Disconnect",
"mssql.manageProfiles":"Manage Connection Profiles",
"mssql.clearPooledConnections":"Clear Pooled Connections",
"mssql.chooseDatabase":"Use Database",
"mssql.chooseLanguageFlavor":"Choose SQL handler for this file",
"mssql.showGettingStarted":"Getting Started Guide",
Expand Down Expand Up @@ -71,7 +72,7 @@
"mssql.connection.emptyPasswordInput":"[Optional] Indicates whether this profile has an empty password explicitly set",
"mssql.azureAuthenticationLibrary":"The library used for the Azure Active Directory authentication flow. Please restart Visual Studio Code after changing this option.",
"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. Please restart Visual Studio Code after changing this option.",
"mssql.enableConnectionPooling":"Enables connection pooling to improve overall connectivity performance. This setting is disabled by default. Visual Studio Code is required to be relaunched when the value is changed.",
"mssql.enableConnectionPooling":"Enables connection pooling to improve overall connectivity performance. This setting is enabled by default. Visual Studio Code is required to be relaunched when the value is changed. To clear pooled connections, run the command: 'MS SQL: Clear Pooled Connections'",
"mssql.shortcuts":"Shortcuts related to the results window",
"mssql.messagesDefaultOpen":"True for the messages pane to be open by default; false for closed",
"mssql.resultsFontFamily":"Set the font family for the results grid; set to blank to use the editor font",
Expand Down
4 changes: 2 additions & 2 deletions src/azure/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as os from 'os';
import { parse } from 'url';
import * as vscode from 'vscode';
import { getProxyAgentOptions } from '../languageservice/proxy';
import {AzureAuthType, IToken } from '../models/contracts/azure';
import { AzureAuthType, IToken } from '../models/contracts/azure';
import * as Constants from './constants';
import { TokenCredentialWrapper } from './credentialWrapper';
import { HttpClient } from './msal/httpClient';
Expand Down Expand Up @@ -93,7 +93,7 @@ export function getEnableConnectionPoolingConfig(): boolean {
return val;
}
}
return false; // default setting
return true; // default setting
}

export function getProxyEnabledHttpClient(): HttpClient {
Expand Down
2 changes: 1 addition & 1 deletion src/configurations/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"service": {
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
"version": "4.8.0.39",
"version": "4.9.0.34",
"downloadFileNames": {
"Windows_86": "win-x86-net7.0.zip",
"Windows_64": "win-x64-net7.0.zip",
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const cmdPauseQueryHistory = 'mssql.pauseQueryHistoryCapture';
export const cmdCommandPaletteQueryHistory = 'mssql.commandPaletteQueryHistory';
export const cmdNewQuery = 'mssql.newQuery';
export const cmdManageConnectionProfiles = 'mssql.manageProfiles';
export const cmdClearPooledConnections = 'mssql.clearPooledConnections';
export const cmdRebuildIntelliSenseCache = 'mssql.rebuildIntelliSenseCache';
export const cmdAddObjectExplorer = 'mssql.addObjectExplorer';
export const cmdObjectExplorerNewQuery = 'mssql.objectExplorerNewQuery';
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ConnectionProfile } from '../models/connectionProfile';
import { ConnectionStore } from '../models/connectionStore';
import { IAccount } from '../models/contracts/azure';
import * as ConnectionContracts from '../models/contracts/connection';
import { ConnectionSummary } from '../models/contracts/connection';
import { ClearPooledConnectionsRequest, ConnectionSummary } from '../models/contracts/connection';
import * as LanguageServiceContracts from '../models/contracts/languageService';
import { EncryptOptions, IConnectionProfile } from '../models/interfaces';
import { PlatformInformation, Runtime } from '../models/platform';
Expand Down Expand Up @@ -502,7 +502,7 @@ export default class ConnectionManager {
sendErrorEvent(
TelemetryViews.ConnectionPrompt,
TelemetryActions.CreateConnectionResult,
new Error (result.errorMessage),
new Error(result.errorMessage),
false,
result.errorNumber?.toString(),
undefined,
Expand Down Expand Up @@ -931,6 +931,10 @@ export default class ConnectionManager {
return this.connectionUI.promptToManageProfiles();
}

public async onClearPooledConnections(): Promise<void> {
return await this._client.sendRequest(ClearPooledConnectionsRequest.type, {});
}

public async onCreateProfile(): Promise<boolean> {
let self = this;
const profile = await self.connectionUI.createAndSaveProfile(self.vscodeWrapper.isEditingSqlFile);
Expand Down
16 changes: 14 additions & 2 deletions src/controllers/mainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export default class MainController implements vscode.Disposable {
this.registerCommand(Constants.cmdRunQuery);
this._event.on(Constants.cmdRunQuery, () => { this.onRunQuery(); });
this.registerCommand(Constants.cmdManageConnectionProfiles);
this._event.on(Constants.cmdRunCurrentStatement, () => { this.onRunCurrentStatement(); });
this.registerCommand(Constants.cmdRunCurrentStatement);
this._event.on(Constants.cmdManageConnectionProfiles, async () => { await this.onManageProfiles(); });
this.registerCommand(Constants.cmdClearPooledConnections);
this._event.on(Constants.cmdClearPooledConnections, async () => { await this.onClearPooledConnections(); });
this.registerCommand(Constants.cmdRunCurrentStatement);
this._event.on(Constants.cmdRunCurrentStatement, () => { this.onRunCurrentStatement(); });
this.registerCommand(Constants.cmdChooseDatabase);
this._event.on(Constants.cmdChooseDatabase, () => { this.runAndLogErrors(this.onChooseDatabase()); });
this.registerCommand(Constants.cmdChooseLanguageFlavor);
Expand Down Expand Up @@ -705,6 +707,16 @@ export default class MainController implements vscode.Disposable {
}
}

/**
* Clears all pooled connections not in active use.
*/
public async onClearPooledConnections(): Promise<void> {
if (this.canRunCommand()) {
await this._connectionMgr.onClearPooledConnections();
return;
}
}

/**
* Let users pick from a list of connections
*/
Expand Down
6 changes: 6 additions & 0 deletions src/models/contracts/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,9 @@ export class DidChangeEncryptionIVKeyParams {
export namespace EncryptionKeysChangedNotification {
export const type = new NotificationType<DidChangeEncryptionIVKeyParams, void>('connection/encryptionKeysChanged');
}

// ------------------------------- < Clear Pooled Connections Request > ---------------------------------------

export namespace ClearPooledConnectionsRequest {
export const type = new RequestType<object, void, void, void>('connection/clearpooledconnections');
}