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

@@ -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