Disabled MARS by default (#88)

* Disabled MARS by default

* Addressing feedback

* Added check for unhandled ObjectDisposedException
This commit is contained in:
Mitchell Sternke
2016-10-10 17:15:26 -07:00
committed by GitHub
parent 8511f5db43
commit a2f2dd7b5e

View File

@@ -182,10 +182,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
// create a sql connection instance // create a sql connection instance
connectionInfo.SqlConnection = connectionInfo.Factory.CreateSqlConnection(connectionString); connectionInfo.SqlConnection = connectionInfo.Factory.CreateSqlConnection(connectionString);
// turning on MARS to avoid break in LanguageService with multiple editors
// we'll remove this once ConnectionService is refactored to not own the LanguageService connection
connectionInfo.ConnectionDetails.MultipleActiveResultSets = true;
// Add a cancellation token source so that the connection OpenAsync() can be cancelled // Add a cancellation token source so that the connection OpenAsync() can be cancelled
using (source = new CancellationTokenSource()) using (source = new CancellationTokenSource())
{ {
@@ -205,7 +201,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
var cancellationTask = Task.Run(() => var cancellationTask = Task.Run(() =>
{ {
source.Token.WaitHandle.WaitOne(); source.Token.WaitHandle.WaitOne();
try
{
source.Token.ThrowIfCancellationRequested(); source.Token.ThrowIfCancellationRequested();
}
catch (ObjectDisposedException)
{
// Ignore
}
}); });
var openTask = Task.Run(async () => { var openTask = Task.Run(async () => {
@@ -393,17 +396,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
var connection = this.ConnectionFactory.CreateSqlConnection(BuildConnectionString(connectionDetails)); var connection = this.ConnectionFactory.CreateSqlConnection(BuildConnectionString(connectionDetails));
connection.Open(); connection.Open();
DbCommand command = connection.CreateCommand(); List<string> results = new List<string>();
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT name FROM sys.databases ORDER BY database_id ASC"; command.CommandText = "SELECT name FROM sys.databases ORDER BY database_id ASC";
command.CommandTimeout = 15; command.CommandTimeout = 15;
command.CommandType = CommandType.Text; command.CommandType = CommandType.Text;
var reader = command.ExecuteReader();
List<string> results = new List<string>(); using (var reader = command.ExecuteReader())
{
while (reader.Read()) while (reader.Read())
{ {
results.Add(reader[0].ToString()); results.Add(reader[0].ToString());
} }
}
}
connection.Close(); connection.Close();