mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Send Error Code with session failed notification (#1773)
This commit is contained in:
@@ -46,6 +46,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public NodeInfo RootNode { get; set; }
|
public NodeInfo RootNode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error number returned from the engine, if any.
|
||||||
|
/// </summary>
|
||||||
|
public int? ErrorNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Error message returned from the engine for a object explorer session failure reason, if any.
|
/// Error message returned from the engine for a object explorer session failure reason, if any.
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
|
using Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlTools.Extensibility;
|
using Microsoft.SqlTools.Extensibility;
|
||||||
@@ -324,6 +325,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
SessionId = uri,
|
SessionId = uri,
|
||||||
|
ErrorNumber = result.Exception != null && result.Exception is SqlException sqlEx ? sqlEx.ErrorCode : null,
|
||||||
ErrorMessage = result.Exception != null ? result.Exception.Message : $"Failed to create session for session id {uri}"
|
ErrorMessage = result.Exception != null ? result.Exception.Message : $"Failed to create session for session id {uri}"
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -361,6 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
Success = true,
|
Success = true,
|
||||||
RootNode = session.Root.ToNodeInfo(),
|
RootNode = session.Root.ToNodeInfo(),
|
||||||
SessionId = uri,
|
SessionId = uri,
|
||||||
|
ErrorNumber = session.ErrorNumber,
|
||||||
ErrorMessage = session.ErrorMessage
|
ErrorMessage = session.ErrorMessage
|
||||||
};
|
};
|
||||||
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, response);
|
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, response);
|
||||||
@@ -524,7 +527,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await SendSessionFailedNotification(uri, ex.Message);
|
int? errorCode = ex is SqlException sqlEx ? sqlEx.ErrorCode : null;
|
||||||
|
await SendSessionFailedNotification(uri, ex.Message, errorCode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,25 +547,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await SendSessionFailedNotification(uri, result.ErrorMessage);
|
await SendSessionFailedNotification(uri, result.ErrorMessage, result.ErrorNumber);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await SendSessionFailedNotification(uri, ex.ToString());
|
int? errorNum = ex is SqlException sqlEx ? sqlEx.Number : null;
|
||||||
|
await SendSessionFailedNotification(uri, ex.ToString(), errorNum);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendSessionFailedNotification(string uri, string errorMessage)
|
private async Task SendSessionFailedNotification(string uri, string errorMessage, int? errorCode)
|
||||||
{
|
{
|
||||||
Logger.Write(TraceEventType.Warning, $"Failed To create OE session: {errorMessage}");
|
Logger.Write(TraceEventType.Warning, $"Failed To create OE session: {errorMessage}");
|
||||||
SessionCreatedParameters result = new SessionCreatedParameters()
|
SessionCreatedParameters result = new SessionCreatedParameters()
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
ErrorMessage = errorMessage,
|
ErrorMessage = errorMessage,
|
||||||
|
ErrorNumber = errorCode,
|
||||||
SessionId = uri
|
SessionId = uri
|
||||||
};
|
};
|
||||||
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, result);
|
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, result);
|
||||||
@@ -809,6 +815,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
|
|
||||||
public ConnectionInfo ConnectionInfo { get; set; }
|
public ConnectionInfo ConnectionInfo { get; set; }
|
||||||
|
|
||||||
|
public int? ErrorNumber { get; set; }
|
||||||
|
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection, bool isDefaultOrSystemDatabase)
|
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection, bool isDefaultOrSystemDatabase)
|
||||||
@@ -822,6 +830,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
session.Root = databaseNode;
|
session.Root = databaseNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response?.ErrorMessage != null)
|
||||||
|
{
|
||||||
|
session.ErrorMessage = response.ErrorMessage;
|
||||||
|
session.ErrorNumber = response.ErrorNumber;
|
||||||
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user