From 803a19d7169ea4a58c7b5a7d6c3e3ea4f6336d81 Mon Sep 17 00:00:00 2001 From: Mitchell Sternke Date: Wed, 21 Sep 2016 11:59:03 -0700 Subject: [PATCH] Made connection errors more user-friendly (#57) --- .../Connection/ConnectionService.cs | 10 +++++++++- .../Connection/Contracts/ConnectResponse.cs | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 6cdd62aa..bc685eff 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -162,8 +162,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection connectionInfo.SqlConnection = connectionInfo.Factory.CreateSqlConnection(connectionString); connectionInfo.SqlConnection.Open(); } - catch(Exception ex) + catch (SqlException ex) { + response.ErrorNumber = ex.Number; + response.ErrorMessage = ex.Message; + response.Messages = ex.ToString(); + return response; + } + catch (Exception ex) + { + response.ErrorMessage = ex.Message; response.Messages = ex.ToString(); return response; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs index 9066efa8..9dcf061e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs @@ -16,10 +16,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts public string ConnectionId { get; set; } /// - /// Gets or sets any connection error messages + /// Gets or sets any detailed connection error messages. /// public string Messages { get; set; } + /// + /// Error message returned from the engine for a connection failure reason, if any. + /// + public string ErrorMessage { get; set; } + + /// + /// Error number returned from the engine for connection failure reason, if any. + /// + public int ErrorNumber { get; set; } + /// /// Information about the connected server. ///