fixed the issue with resources not disposed correctly (#439)

* fixed the issue with resources not disposed correctly

* disposing language service at shutdown
This commit is contained in:
Leila Lali
2017-08-21 14:32:48 -07:00
committed by GitHub
parent 39dedd88e0
commit 1511f73672
7 changed files with 108 additions and 71 deletions

View File

@@ -1119,27 +1119,30 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
throw new ArgumentException("sourceXml");
}
MemoryStream memoryStream = new MemoryStream();
StreamWriter streamWriter = new StreamWriter(memoryStream);
using (MemoryStream memoryStream = new MemoryStream())
{
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
// Writes the xml to the memory stream
streamWriter.Write(sourceXml);
streamWriter.Flush();
// Writes the xml to the memory stream
streamWriter.Write(sourceXml);
streamWriter.Flush();
// Resets the stream to the beginning
memoryStream.Seek(0, SeekOrigin.Begin);
// Resets the stream to the beginning
memoryStream.Seek(0, SeekOrigin.Begin);
// Creates the XML reader from the stream
// and moves it to the correct node
XmlReader xmlReader = XmlReader.Create(memoryStream);
xmlReader.MoveToContent();
// Creates the XML reader from the stream
// and moves it to the correct node
XmlReader xmlReader = XmlReader.Create(memoryStream);
xmlReader.MoveToContent();
// generate the xml document
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(xmlReader.ReadOuterXml());
// generate the xml document
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(xmlReader.ReadOuterXml());
return xmlDocument;
return xmlDocument;
}
}
}
#endregion

View File

@@ -647,17 +647,20 @@ WHERE do.database_id = @DbID
{ //If it's under v12 we need to query the master DB directly since that has the views containing the necessary information
using (var conn = new SqlConnection(context.Server.ConnectionContext.ConnectionString))
{
var cmd = new SqlCommand(dbSloQuery, conn);
cmd.Parameters.AddWithValue("@DbID", db.ID);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
using (var cmd = new SqlCommand(dbSloQuery, conn))
{
this.configuredServiceLevelObjective = reader["configured_slo_name"].ToString();
this.currentServiceLevelObjective = reader["current_slo_name"].ToString();
break; //Got our service level objective so we're done
cmd.Parameters.AddWithValue("@DbID", db.ID);
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
this.configuredServiceLevelObjective = reader["configured_slo_name"].ToString();
this.currentServiceLevelObjective = reader["current_slo_name"].ToString();
break; //Got our service level objective so we're done
}
}
}
}
}
}

View File

@@ -177,33 +177,35 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
//Altering the DB needs to be done on the master DB
using (var conn = new SqlConnection(this.context.ServerConnection.GetDatabaseConnection("master").ConnectionString))
{
var cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
{
using (var cmd = new SqlCommand())
{
cmd.Connection = conn;
conn.Open();
//Only run the alter statements for modifications made. This is mostly to allow the non-Azure specific
//properties to be updated when a SLO change is in progress, but it also is beneficial to save trips to the
//server whenever we can (especially when Azure is concerned)
if (currentState.azureEdition != originalState.azureEdition ||
currentState.currentServiceLevelObjective != originalState.currentServiceLevelObjective ||
currentState.maxSize != originalState.maxSize)
{
cmd.CommandText = alterDbPropertiesStatement;
cmd.ExecuteNonQuery();
}
//Only run the alter statements for modifications made. This is mostly to allow the non-Azure specific
//properties to be updated when a SLO change is in progress, but it also is beneficial to save trips to the
//server whenever we can (especially when Azure is concerned)
if (currentState.azureEdition != originalState.azureEdition ||
currentState.currentServiceLevelObjective != originalState.currentServiceLevelObjective ||
currentState.maxSize != originalState.maxSize)
{
cmd.CommandText = alterDbPropertiesStatement;
cmd.ExecuteNonQuery();
}
if (currentState.recursiveTriggers != originalState.recursiveTriggers)
{
cmd.CommandText = alterAzureDbRecursiveTriggersEnabledStatement;
cmd.ExecuteNonQuery();
}
if (currentState.recursiveTriggers != originalState.recursiveTriggers)
{
cmd.CommandText = alterAzureDbRecursiveTriggersEnabledStatement;
cmd.ExecuteNonQuery();
}
if (currentState.isReadOnly != originalState.isReadOnly)
{
cmd.CommandText = alterAzureDbIsReadOnlyStatement;
cmd.ExecuteNonQuery();
}
if (currentState.isReadOnly != originalState.isReadOnly)
{
cmd.CommandText = alterAzureDbIsReadOnlyStatement;
cmd.ExecuteNonQuery();
}
}
}
//Because we didn't use SMO to do the alter we should refresh the DB object so it picks up the correct properties