Handle connection exceptions and add error callback (#126)

This commit is contained in:
Sharon Ravindran
2016-10-31 11:25:51 -07:00
committed by GitHub
parent 69bbb652da
commit 29b7854ec1
3 changed files with 41 additions and 1 deletions

View File

@@ -102,6 +102,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// <param name="q">The query that completed</param>
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>
/// Callback for when the query has completed successfully
/// </summary>
@@ -112,6 +118,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// </summary>
public event QueryAsyncEventHandler QueryFailed;
/// <summary>
/// Callback for when the query connection has failed
/// </summary>
public event QueryAsyncErrorEventHandler QueryConnectionException;
/// <summary>
/// The batches underneath this query
/// </summary>
@@ -241,7 +252,19 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
// TODO: Don't create a new connection every time, see TFS #834978
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;
if (sqlConn != null)