From d4eadd6ef1cacb10f97f58d1f549bf275ac7b76a Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 6 Oct 2017 14:47:58 -0700 Subject: [PATCH 1/2] Check for "Account Locked" SQL Exception 18486 while connecitng to SQL Server 2008/2012 and throw Exception --- .../java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java | 1 + .../java/com/microsoft/sqlserver/jdbc/SQLServerException.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 730f13bf7..35578f24b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -1991,6 +1991,7 @@ else if (null == currentPrimaryPlaceHolder) { catch (SQLServerException sqlex) { if ((SQLServerException.LOGON_FAILED == sqlex.getErrorCode()) // actual logon failed, i.e. bad password || (SQLServerException.PASSWORD_EXPIRED == sqlex.getErrorCode()) // actual logon failed, i.e. password isExpired + || (SQLServerException.USER_ACCOUNT_LOCKED == sqlex.getErrorCode()) // actual logon failed, i.e. password isExpired || (SQLServerException.DRIVER_ERROR_INVALID_TDS == sqlex.getDriverErrorCode()) // invalid TDS received from server || (SQLServerException.DRIVER_ERROR_SSL_FAILED == sqlex.getDriverErrorCode()) // failure negotiating SSL || (SQLServerException.DRIVER_ERROR_INTERMITTENT_TLS_FAILED == sqlex.getDriverErrorCode()) // failure TLS1.2 diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java index e8ed55d5a..20e18255b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java @@ -59,6 +59,7 @@ public final class SQLServerException extends java.sql.SQLException { // SQL error values (from sqlerrorcodes.h) static final int LOGON_FAILED = 18456; static final int PASSWORD_EXPIRED = 18488; + static final int USER_ACCOUNT_LOCKED = 18486; static java.util.logging.Logger exLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.internals.SQLServerException"); // Facility for driver-specific error codes From 4a1409a848b8e578de51d9de8f7d9c5c8edc9839 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 6 Oct 2017 15:30:34 -0700 Subject: [PATCH 2/2] Updated comment for Locked User Account in SQLServerConnection.java --- .../java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 35578f24b..be9056c60 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -1991,7 +1991,7 @@ else if (null == currentPrimaryPlaceHolder) { catch (SQLServerException sqlex) { if ((SQLServerException.LOGON_FAILED == sqlex.getErrorCode()) // actual logon failed, i.e. bad password || (SQLServerException.PASSWORD_EXPIRED == sqlex.getErrorCode()) // actual logon failed, i.e. password isExpired - || (SQLServerException.USER_ACCOUNT_LOCKED == sqlex.getErrorCode()) // actual logon failed, i.e. password isExpired + || (SQLServerException.USER_ACCOUNT_LOCKED == sqlex.getErrorCode()) // actual logon failed, i.e. user account locked || (SQLServerException.DRIVER_ERROR_INVALID_TDS == sqlex.getDriverErrorCode()) // invalid TDS received from server || (SQLServerException.DRIVER_ERROR_SSL_FAILED == sqlex.getDriverErrorCode()) // failure negotiating SSL || (SQLServerException.DRIVER_ERROR_INTERMITTENT_TLS_FAILED == sqlex.getDriverErrorCode()) // failure TLS1.2