Support clearing pooled connections (#2214)

This commit is contained in:
Cheena Malhotra
2023-09-07 12:03:56 -07:00
committed by GitHub
parent d31f247b9d
commit 703691e897
2 changed files with 37 additions and 0 deletions

View File

@@ -1128,6 +1128,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
serviceHost.SetRequestHandler(ChangeDatabaseRequest.Type, HandleChangeDatabaseRequest, true);
serviceHost.SetRequestHandler(GetConnectionStringRequest.Type, HandleGetConnectionStringRequest, true);
serviceHost.SetRequestHandler(BuildConnectionInfoRequest.Type, HandleBuildConnectionInfoRequest, true);
serviceHost.SetRequestHandler(ClearPooledConnectionsRequest.Type, HandleClearPooledConnectionsRequest, true);
serviceHost.SetEventHandler(EncryptionKeysChangedNotification.Type, HandleEncryptionKeysNotificationEvent, false);
}
@@ -1689,6 +1690,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
}
}
/// <summary>
/// Clears all pooled connections from SqlConnection pool, releasing open connection sockets not actively in use.
/// </summary>
/// <param name="_">Request param</param>
/// <param name="requestContext">Request Context</param>
/// <returns></returns>
public async Task HandleClearPooledConnectionsRequest(object _, RequestContext<bool> requestContext)
{
// Run a detached task to clear pools in backend.
await Task.Factory.StartNew(() => Task.Run(async () => {
SqlConnection.ClearAllPools();
Logger.Verbose("Cleared all pooled connections successfully.");
await requestContext.SendResult(true);
}));
}
public ConnectionDetails ParseConnectionString(string connectionString)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

View File

@@ -0,0 +1,18 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
{
/// <summary>
/// Clear Pooled connectins request
/// </summary>
public class ClearPooledConnectionsRequest
{
public static readonly
RequestType<object, bool> Type = RequestType<object, bool>.Create("connection/clearpooledconnections");
}
}