mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 01:25:41 -05:00
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:
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user