diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs index e5c85450..a7c470f2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Query.cs @@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution { get { - if (!HasExecuted && !HasCancelled) + if (!HasExecuted && !HasCancelled && !HasErrored) { throw new InvalidOperationException("Query has not been executed."); } @@ -264,6 +264,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution /// public bool HasCancelled { get; private set; } + /// + /// if the query has errored out (before batch execution started) + /// + public bool HasErrored { get; private set; } + /// /// The text of the query to execute /// @@ -393,7 +398,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution } return; } - + // Locate and setup the connection DbConnection queryConnection = await ConnectionService.Instance.GetOrOpenConnection(editorConnection.OwnerUri, ConnectionType.Query); sqlConn = queryConnection as ReliableSqlConnection; @@ -438,6 +443,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution } catch (Exception e) { + HasErrored = true; if (e is OperationCanceledException) { await BatchMessageSent(new ResultMessage(SR.QueryServiceQueryCancelled, false, null)); diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs index 027ba542..2eece988 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -638,7 +638,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution // if any oldQuery exists on the executeParams.OwnerUri but it has not yet executed, // then shouldn't we cancel and clean out that query since we are about to create a new query object on the current OwnerUri. // - if (ActiveQueries.TryGetValue(executeParams.OwnerUri, out oldQuery) && (oldQuery.HasExecuted || oldQuery.HasCancelled)) + if (ActiveQueries.TryGetValue(executeParams.OwnerUri, out oldQuery) && (oldQuery.HasExecuted || oldQuery.HasCancelled || oldQuery.HasErrored)) { oldQuery.Dispose(); ActiveQueries.TryRemove(executeParams.OwnerUri, out oldQuery);