diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
index d485ca97..b0fa53b0 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
@@ -22,7 +22,6 @@ 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
{
@@ -38,6 +37,12 @@ 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
///
@@ -1159,18 +1164,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
catch (Exception ex)
{
newResponse.Result = false;
- 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 = 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 += Environment.NewLine + Environment.NewLine + SR.PasswordChangeEmptyPasswordRetry;
}
- else if (newResponse.ErrorMessage.Contains(SR.PasswordChangeDNMReqs))
+ else if (errorCode == DoesNotMeetPWReqs)
{
newResponse.ErrorMessage += Environment.NewLine + Environment.NewLine + SR.PasswordChangeDNMReqsRetry;
}
- else if (newResponse.ErrorMessage.Contains(SR.PasswordChangePWCannotBeUsed))
+ else if (errorCode == PWCannotBeUsed)
{
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 070e8359..449a3228 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
@@ -77,14 +77,6 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
- public static string PasswordChangeDNMReqs
- {
- get
- {
- return Keys.GetString(Keys.PasswordChangeDNMReqs);
- }
- }
-
public static string PasswordChangeDNMReqsRetry
{
get
@@ -93,14 +85,6 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
- public static string PasswordChangePWCannotBeUsed
- {
- get
- {
- return Keys.GetString(Keys.PasswordChangePWCannotBeUsed);
- }
- }
-
public static string PasswordChangePWCannotBeUsedRetry
{
get
@@ -10136,15 +10120,9 @@ 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 a5d8d954..71f8df03 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
@@ -176,18 +176,10 @@
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 07abb28e..930bb977 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
@@ -51,12 +51,8 @@ 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 ba07576f..f1427633 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
@@ -6515,21 +6515,11 @@ 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.