Reopen connections prior to creating query execution data readers (#704)

* Reopen connections prior to creating query execution data readers

* Reopen connection if an exception was rasied executing the query

* Fix unit tests
This commit is contained in:
Karl Burtram
2018-10-08 12:41:04 -07:00
committed by GitHub
parent acf7634425
commit 7c1710d396
4 changed files with 39 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
using Microsoft.SqlTools.Utility;
using System.Globalization;
using System.Collections.ObjectModel;
using Microsoft.SqlTools.ServiceLayer.Connection;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
@@ -364,6 +365,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
// so add a newline to the end of the query. See https://github.com/Microsoft/sqlopsstudio/issues/1424
dbCommand.CommandText += Environment.NewLine;
ConnectionService.EnsureConnectionIsOpen(conn);
// Fetch schema info separately, since CommandBehavior.KeyInfo will include primary
// key columns in the result set, even if they weren't part of the select statement.
// Extra key columns get added to the end, so just correlate via Column Ordinal.
@@ -380,6 +383,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
}
ConnectionService.EnsureConnectionIsOpen(conn);
// Execute the command to get back a reader
using (DbDataReader reader = await dbCommand.ExecuteReaderAsync(cancellationToken))
{

View File

@@ -436,6 +436,15 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
ConnectionService.Instance.ChangeConnectionDatabaseContext(editorConnection.OwnerUri, newDatabaseName);
}
foreach (Batch b in Batches)
{
if (b.HasError)
{
ConnectionService.EnsureConnectionIsOpen(sqlConn, forceReopen: true);
break;
}
}
}
}