mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Support clearing pooled connections (#2214)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user