Simplify connection cleanup and clear pools to prevent lingering connections (#2199)

This commit is contained in:
Cory Rivera
2023-08-30 14:38:24 -07:00
committed by GitHub
parent c73ab55055
commit 724d533090
6 changed files with 505 additions and 511 deletions

View File

@@ -1115,6 +1115,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
} }
this.managedConnection = null; this.managedConnection = null;
} }
if (this.serverConnection != null)
{
if (disposing && this.ownConnection)
{
this.serverConnection.Disconnect();
}
this.serverConnection = null;
}
} }
catch (Exception) catch (Exception)
{ {

View File

@@ -16,6 +16,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement.Contracts
/// </summary> /// </summary>
public string ObjectUrn { get; set; } public string ObjectUrn { get; set; }
/// <summary> /// <summary>
/// The target database name.
/// </summary>
public string Database { get; set; }
/// <summary>
/// URI of the underlying connection for this request /// URI of the underlying connection for this request
/// </summary> /// </summary>
public string ConnectionUri { get; set; } public string ConnectionUri { get; set; }

View File

@@ -16,6 +16,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement.Contracts
/// </summary> /// </summary>
public string ObjectUrn { get; set; } public string ObjectUrn { get; set; }
/// <summary> /// <summary>
/// The target database name.
/// </summary>
public string Database { get; set; }
/// <summary>
/// URI of the underlying connection for this request /// URI of the underlying connection for this request
/// </summary> /// </summary>
public string ConnectionUri { get; set; } public string ConnectionUri { get; set; }

View File

@@ -32,44 +32,41 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
public override Task<InitializeViewResult> InitializeObjectView(InitializeViewRequestParams requestParams) public override Task<InitializeViewResult> InitializeObjectView(InitializeViewRequestParams requestParams)
{ {
ConnectionInfo connInfo = this.GetConnectionInfo(requestParams.ConnectionUri); ConnectionInfo connInfo = this.GetConnectionInfo(requestParams.ConnectionUri);
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
using (var context = new ServerViewContext(requestParams, ConnectionService.OpenServerConnection(connInfo, ObjectManagementService.ApplicationName))) ServerPrototype prototype = new ServerPrototype(dataContainer);
if (prototype != null)
{ {
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); this.serverViewInfo.ObjectInfo = new ServerInfo()
ServerPrototype prototype = new ServerPrototype(dataContainer);
if (prototype != null)
{ {
this.serverViewInfo.ObjectInfo = new ServerInfo() Name = prototype.Name,
{ HardwareGeneration = prototype.HardwareGeneration,
Name = prototype.Name, Language = prototype.Language,
HardwareGeneration = prototype.HardwareGeneration, MemoryInMB = prototype.MemoryInMB,
Language = prototype.Language, OperatingSystem = prototype.OperatingSystem,
MemoryInMB = prototype.MemoryInMB, Platform = prototype.Platform,
OperatingSystem = prototype.OperatingSystem, Processors = prototype.Processors,
Platform = prototype.Platform, IsClustered = prototype.IsClustered,
Processors = prototype.Processors, IsHadrEnabled = prototype.IsHadrEnabled,
IsClustered = prototype.IsClustered, IsPolyBaseInstalled = prototype.IsPolyBaseInstalled,
IsHadrEnabled = prototype.IsHadrEnabled, IsXTPSupported = prototype.IsXTPSupported,
IsPolyBaseInstalled = prototype.IsPolyBaseInstalled, Product = prototype.Product,
IsXTPSupported = prototype.IsXTPSupported, ReservedStorageSizeMB = prototype.ReservedStorageSizeMB,
Product = prototype.Product, RootDirectory = prototype.RootDirectory,
ReservedStorageSizeMB = prototype.ReservedStorageSizeMB, ServerCollation = prototype.ServerCollation,
RootDirectory = prototype.RootDirectory, ServiceTier = prototype.ServiceTier,
ServerCollation = prototype.ServerCollation, StorageSpaceUsageInMB = prototype.StorageSpaceUsageInMB,
ServiceTier = prototype.ServiceTier, Version = prototype.Version,
StorageSpaceUsageInMB = prototype.StorageSpaceUsageInMB, MinServerMemory = prototype.MinServerMemory,
Version = prototype.Version, MaxServerMemory = prototype.MaxServerMemory,
MinServerMemory = prototype.MinServerMemory, AutoProcessorAffinityMaskForAll = prototype.AutoProcessorAffinityMaskForAll,
MaxServerMemory = prototype.MaxServerMemory, AutoProcessorAffinityIOMaskForAll = prototype.AutoProcessorAffinityIOMaskForAll,
AutoProcessorAffinityMaskForAll = prototype.AutoProcessorAffinityMaskForAll, NumaNodes = prototype.NumaNodes
AutoProcessorAffinityIOMaskForAll = prototype.AutoProcessorAffinityIOMaskForAll, };
NumaNodes = prototype.NumaNodes
};
}
return Task.FromResult(new InitializeViewResult { ViewInfo = this.serverViewInfo, Context = context });
} }
var context = new ServerViewContext(requestParams);
return Task.FromResult(new InitializeViewResult { ViewInfo = this.serverViewInfo, Context = context });
} }
public override Task Save(ServerViewContext context, ServerInfo obj) public override Task Save(ServerViewContext context, ServerInfo obj)

View File

@@ -3,16 +3,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
using Microsoft.SqlServer.Management.Common;
namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
{ {
public class ServerViewContext : SqlObjectViewContext public class ServerViewContext : SqlObjectViewContext
{ {
public ServerConnection Connection { get; } public ServerViewContext(Contracts.InitializeViewRequestParams parameters) : base(parameters)
public ServerViewContext(Contracts.InitializeViewRequestParams parameters, ServerConnection connection) : base(parameters)
{ {
this.Connection = connection;
} }
public override void Dispose() public override void Dispose()