mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Proposed fix for : 3653 : Cancel not working even after disconnecting (#797)
* Proposed changes to stop query execution if an exception has occured before/during batch execution * Sending the error message was causing a test to fail - so removing for now. We can update the test to expect this is needed.
This commit is contained in:
@@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!HasExecuted && !HasCancelled)
|
if (!HasExecuted && !HasCancelled && !HasErrored)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Query has not been executed.");
|
throw new InvalidOperationException("Query has not been executed.");
|
||||||
}
|
}
|
||||||
@@ -264,6 +264,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasCancelled { get; private set; }
|
public bool HasCancelled { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// if the query has errored out (before batch execution started)
|
||||||
|
/// </summary>
|
||||||
|
public bool HasErrored { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text of the query to execute
|
/// The text of the query to execute
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -393,7 +398,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locate and setup the connection
|
// Locate and setup the connection
|
||||||
DbConnection queryConnection = await ConnectionService.Instance.GetOrOpenConnection(editorConnection.OwnerUri, ConnectionType.Query);
|
DbConnection queryConnection = await ConnectionService.Instance.GetOrOpenConnection(editorConnection.OwnerUri, ConnectionType.Query);
|
||||||
sqlConn = queryConnection as ReliableSqlConnection;
|
sqlConn = queryConnection as ReliableSqlConnection;
|
||||||
@@ -438,6 +443,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
HasErrored = true;
|
||||||
if (e is OperationCanceledException)
|
if (e is OperationCanceledException)
|
||||||
{
|
{
|
||||||
await BatchMessageSent(new ResultMessage(SR.QueryServiceQueryCancelled, false, null));
|
await BatchMessageSent(new ResultMessage(SR.QueryServiceQueryCancelled, false, null));
|
||||||
|
|||||||
@@ -638,7 +638,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
// if any oldQuery exists on the executeParams.OwnerUri but it has not yet executed,
|
// 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.
|
// 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();
|
oldQuery.Dispose();
|
||||||
ActiveQueries.TryRemove(executeParams.OwnerUri, out oldQuery);
|
ActiveQueries.TryRemove(executeParams.OwnerUri, out oldQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user