diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypeHandler.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypeHandler.cs index acc94412..6dc254fc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypeHandler.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectManagement/ObjectTypeHandler.cs @@ -74,6 +74,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement throw new Exception(SR.ObjectNotRenamable(objectUrn)); } } + // If connection is not instantiated in the using statement, it can be leaked here, therefore close explicitly. + if(serverConnection.SqlConnectionObject.State == System.Data.ConnectionState.Open) + { + serverConnection.SqlConnectionObject.Close(); + } return Task.CompletedTask; }