Do not use ReliableCommand in the query execution service (#66)

* Do not use ReliableCommand in the query execution service.

* Fixing the logic to remove InfoMessage handlers from ReliableSqlConnection

* Adding test to query UDT
This commit is contained in:
Brian O'Neill
2016-09-26 15:42:48 -07:00
committed by GitHub
parent 5a198e3f45
commit 57278d9322
5 changed files with 73 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Linq;
using System.Threading;
@@ -134,16 +135,26 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
try
{
DbCommand command = null;
// Register the message listener to *this instance* of the batch
// Note: This is being done to associate messages with batches
ReliableSqlConnection sqlConn = conn as ReliableSqlConnection;
if (sqlConn != null)
{
sqlConn.GetUnderlyingConnection().InfoMessage += StoreDbMessage;
command = sqlConn.GetUnderlyingConnection().CreateCommand();
}
else
{
command = conn.CreateCommand();
}
// Make sure we aren't using a ReliableCommad since we do not want automatic retry
Debug.Assert(!(command is ReliableSqlConnection.ReliableSqlCommand), "ReliableSqlCommand command should not be used to execute queries");
// Create a command that we'll use for executing the query
using (DbCommand command = conn.CreateCommand())
using (command)
{
command.CommandText = BatchText;
command.CommandType = CommandType.Text;
@@ -190,10 +201,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
finally
{
// Remove the message event handler from the connection
SqlConnection sqlConn = conn as SqlConnection;
ReliableSqlConnection sqlConn = conn as ReliableSqlConnection;
if (sqlConn != null)
{
sqlConn.InfoMessage -= StoreDbMessage;
sqlConn.GetUnderlyingConnection().InfoMessage -= StoreDbMessage;
}
// Mark that we have executed

View File

@@ -195,10 +195,21 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
sqlConn.GetUnderlyingConnection().InfoMessage += OnInfoMessage;
}
// We need these to execute synchronously, otherwise the user will be very unhappy
foreach (Batch b in Batches)
try
{
await b.Execute(conn, cancellationSource.Token);
// We need these to execute synchronously, otherwise the user will be very unhappy
foreach (Batch b in Batches)
{
await b.Execute(conn, cancellationSource.Token);
}
}
finally
{
if (sqlConn != null)
{
// Subscribe to database informational messages
sqlConn.GetUnderlyingConnection().InfoMessage -= OnInfoMessage;
}
}
// TODO: Close connection after eliminating using statement for above TODO