From a2f2dd7b5e50557c131b2e6a95e315a729f7bd82 Mon Sep 17 00:00:00 2001 From: Mitchell Sternke Date: Mon, 10 Oct 2016 17:15:26 -0700 Subject: [PATCH] Disabled MARS by default (#88) * Disabled MARS by default * Addressing feedback * Added check for unhandled ObjectDisposedException --- .../Connection/ConnectionService.cs | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 36e86791..9ef9a23c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -182,10 +182,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection // create a sql connection instance 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 using (source = new CancellationTokenSource()) { @@ -205,7 +201,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection var cancellationTask = Task.Run(() => { source.Token.WaitHandle.WaitOne(); - source.Token.ThrowIfCancellationRequested(); + try + { + source.Token.ThrowIfCancellationRequested(); + } + catch (ObjectDisposedException) + { + // Ignore + } }); var openTask = Task.Run(async () => { @@ -393,16 +396,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection var connection = this.ConnectionFactory.CreateSqlConnection(BuildConnectionString(connectionDetails)); connection.Open(); - DbCommand command = connection.CreateCommand(); - command.CommandText = "SELECT name FROM sys.databases ORDER BY database_id ASC"; - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - var reader = command.ExecuteReader(); - List results = new List(); - while (reader.Read()) + using (DbCommand command = connection.CreateCommand()) { - results.Add(reader[0].ToString()); + command.CommandText = "SELECT name FROM sys.databases ORDER BY database_id ASC"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + results.Add(reader[0].ToString()); + } + } } connection.Close();