diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
index b0fa53b0..d485ca97 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
@@ -22,6 +22,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
using System.Diagnostics;
+using System.Text.RegularExpressions;
namespace Microsoft.SqlTools.ServiceLayer.Connection
{
@@ -37,12 +38,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
public const int MaxServerlessReconnectTries = 5; // Max number of tries to wait for a serverless database to start up when its paused before giving up.
- // SQL Error Code Constants
- // Referenced from: https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors?view=sql-server-ver16
- private const int DoesNotMeetPWReqs = 18466; // Password does not meet complexity requirements.
- private const int PWCannotBeUsed = 18463; // Password cannot be used at this time.
-
-
///
/// Singleton service instance
///
@@ -1164,25 +1159,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
catch (Exception ex)
{
newResponse.Result = false;
- newResponse.ErrorMessage = ex.Message;
- int errorCode = 0;
-
- if ((ex.InnerException as SqlException) != null && (ex.InnerException as SqlException)?.Errors.Count != 0)
- {
- SqlError endError = (ex.InnerException as SqlException).Errors[0];
- newResponse.ErrorMessage = endError.Message;
- errorCode = endError.Number;
- }
-
- if (errorCode == 0 && newResponse.ErrorMessage.Equals(SR.PasswordChangeEmptyPassword))
+ newResponse.ErrorMessage = ex.InnerException != null ? (ex.Message + Environment.NewLine + Environment.NewLine + ex.InnerException.Message) : ex.Message;
+ newResponse.ErrorMessage = Regex.Replace(newResponse.ErrorMessage, @"\r?\nChanged database context to '\w+'\.", "");
+ newResponse.ErrorMessage = Regex.Replace(newResponse.ErrorMessage, @"\r?\nChanged language setting to \w+\.", "");
+ if (newResponse.ErrorMessage.Equals(SR.PasswordChangeEmptyPassword))
{
newResponse.ErrorMessage += Environment.NewLine + Environment.NewLine + SR.PasswordChangeEmptyPasswordRetry;
}
- else if (errorCode == DoesNotMeetPWReqs)
+ else if (newResponse.ErrorMessage.Contains(SR.PasswordChangeDNMReqs))
{
newResponse.ErrorMessage += Environment.NewLine + Environment.NewLine + SR.PasswordChangeDNMReqsRetry;
}
- else if (errorCode == PWCannotBeUsed)
+ else if (newResponse.ErrorMessage.Contains(SR.PasswordChangePWCannotBeUsed))
{
newResponse.ErrorMessage += Environment.NewLine + Environment.NewLine + SR.PasswordChangePWCannotBeUsedRetry;
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
index 449a3228..070e8359 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
@@ -77,6 +77,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
+ public static string PasswordChangeDNMReqs
+ {
+ get
+ {
+ return Keys.GetString(Keys.PasswordChangeDNMReqs);
+ }
+ }
+
public static string PasswordChangeDNMReqsRetry
{
get
@@ -85,6 +93,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
+ public static string PasswordChangePWCannotBeUsed
+ {
+ get
+ {
+ return Keys.GetString(Keys.PasswordChangePWCannotBeUsed);
+ }
+ }
+
public static string PasswordChangePWCannotBeUsedRetry
{
get
@@ -10120,9 +10136,15 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string PasswordChangeEmptyPasswordRetry = "PasswordChangeEmptyPasswordRetry";
+ public const string PasswordChangeDNMReqs = "PasswordChangeDNMReqs";
+
+
public const string PasswordChangeDNMReqsRetry = "PasswordChangeDNMReqsRetry";
+ public const string PasswordChangePWCannotBeUsed = "PasswordChangePWCannotBeUsed";
+
+
public const string PasswordChangePWCannotBeUsedRetry = "PasswordChangePWCannotBeUsedRetry";
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
index 71f8df03..a5d8d954 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
@@ -176,10 +176,18 @@
Press OK to input a new password that is not empty.
+
+ password does not meet operating system policy requirements
+
+
Press OK to input a new password that meets operating system policy requirements.
+
+ password cannot be used at this time
+
+
Press OK to input a different password.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
index 930bb977..07abb28e 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
@@ -51,8 +51,12 @@ PasswordChangeEmptyPassword = New password cannot be empty
PasswordChangeEmptyPasswordRetry = Press OK to input a new password that is not empty.
+PasswordChangeDNMReqs = password does not meet operating system policy requirements
+
PasswordChangeDNMReqsRetry = Press OK to input a new password that meets operating system policy requirements.
+PasswordChangePWCannotBeUsed = password cannot be used at this time
+
PasswordChangePWCannotBeUsedRetry = Press OK to input a different password.
### Connection Params Validation Errors
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
index f1427633..ba07576f 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
@@ -6515,11 +6515,21 @@ The Query Processor estimates that implementing the following index could improv
Press OK to input a new password that is not empty.
+
+ password does not meet operating system policy requirements
+ password does not meet operating system policy requirements
+
+ Press OK to input a new password that meets operating system policy requirements.Press OK to input a new password that meets operating system policy requirements.
+
+ password cannot be used at this time
+ password cannot be used at this time
+
+ Press OK to input a different password.Press OK to input a different password.