mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Handle connection exceptions and add error callback (#126)
This commit is contained in:
committed by
Karl Burtram
parent
a27c182a0f
commit
6937e46c1b
@@ -21,6 +21,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
|||||||
/// Summaries of the result sets that were returned with the query
|
/// Summaries of the result sets that were returned with the query
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BatchSummary[] BatchSummaries { get; set; }
|
public BatchSummary[] BatchSummaries { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error message, if any
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QueryExecuteCompleteEvent
|
public class QueryExecuteCompleteEvent
|
||||||
|
|||||||
@@ -102,6 +102,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// <param name="q">The query that completed</param>
|
/// <param name="q">The query that completed</param>
|
||||||
public delegate Task QueryAsyncEventHandler(Query q);
|
public delegate Task QueryAsyncEventHandler(Query q);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delegate type for callback when a query connection fails
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="q">The query that completed</param>
|
||||||
|
public delegate Task QueryAsyncErrorEventHandler(string message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for when the query has completed successfully
|
/// Callback for when the query has completed successfully
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -112,6 +118,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event QueryAsyncEventHandler QueryFailed;
|
public event QueryAsyncEventHandler QueryFailed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Callback for when the query connection has failed
|
||||||
|
/// </summary>
|
||||||
|
public event QueryAsyncErrorEventHandler QueryConnectionException;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The batches underneath this query
|
/// The batches underneath this query
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -241,7 +252,19 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
// TODO: Don't create a new connection every time, see TFS #834978
|
// TODO: Don't create a new connection every time, see TFS #834978
|
||||||
using (DbConnection conn = editorConnection.Factory.CreateSqlConnection(connectionString))
|
using (DbConnection conn = editorConnection.Factory.CreateSqlConnection(connectionString))
|
||||||
{
|
{
|
||||||
await conn.OpenAsync();
|
try
|
||||||
|
{
|
||||||
|
await conn.OpenAsync();
|
||||||
|
}
|
||||||
|
catch(Exception exception)
|
||||||
|
{
|
||||||
|
this.HasExecuted = true;
|
||||||
|
if (QueryConnectionException != null)
|
||||||
|
{
|
||||||
|
await QueryConnectionException(exception.Message);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ReliableSqlConnection sqlConn = conn as ReliableSqlConnection;
|
ReliableSqlConnection sqlConn = conn as ReliableSqlConnection;
|
||||||
if (sqlConn != null)
|
if (sqlConn != null)
|
||||||
|
|||||||
@@ -427,8 +427,20 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
await requestContext.SendEvent(QueryExecuteCompleteEvent.Type, eventParams);
|
await requestContext.SendEvent(QueryExecuteCompleteEvent.Type, eventParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Query.QueryAsyncErrorEventHandler errorCallback = async errorMessage =>
|
||||||
|
{
|
||||||
|
// Send back the error message
|
||||||
|
QueryExecuteCompleteParams eventParams = new QueryExecuteCompleteParams
|
||||||
|
{
|
||||||
|
OwnerUri = executeParams.OwnerUri,
|
||||||
|
Message = errorMessage
|
||||||
|
};
|
||||||
|
await requestContext.SendEvent(QueryExecuteCompleteEvent.Type, eventParams);
|
||||||
|
};
|
||||||
|
|
||||||
query.QueryCompleted += callback;
|
query.QueryCompleted += callback;
|
||||||
query.QueryFailed += callback;
|
query.QueryFailed += callback;
|
||||||
|
query.QueryConnectionException += errorCallback;
|
||||||
|
|
||||||
// Launch this as an asynchronous task
|
// Launch this as an asynchronous task
|
||||||
query.Execute();
|
query.Execute();
|
||||||
|
|||||||
Reference in New Issue
Block a user