Only register message handler once for GO N queries (#611)

This commit is contained in:
Matt Irvine
2018-05-02 10:16:56 -07:00
committed by Karl Burtram
parent 7415c529f3
commit b81ba929ba

View File

@@ -242,6 +242,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
await BatchStart(this);
}
// 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 += ServerMessageHandler;
}
try
{
@@ -262,7 +270,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
finally
{
// Remove the message event handler from the connection
ReliableSqlConnection sqlConn = conn as ReliableSqlConnection;
if (sqlConn != null)
{
sqlConn.GetUnderlyingConnection().InfoMessage -= ServerMessageHandler;
@@ -438,9 +445,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
DbCommand dbCommand;
if (sqlConn != null)
{
// Register the message listener to *this instance* of the batch
// Note: This is being done to associate messages with batches
sqlConn.GetUnderlyingConnection().InfoMessage += ServerMessageHandler;
dbCommand = sqlConn.GetUnderlyingConnection().CreateCommand();
// Add a handler for when the command completes