diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 377f45859..9b6fab643 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -116,6 +116,8 @@ public class SQLServerConnection implements ISQLServerConnection { private byte[] accessTokenInByte = null; private SqlFedAuthToken fedAuthToken = null; + + private String originalHostNameInCertificate = null; static class Sha1HashKey { private byte[] bytes; @@ -401,7 +403,7 @@ private enum State { ServerPortPlaceHolder getRoutingInfo() { return routingInfo; } - + // Permission targets private static final String callAbortPerm = "callAbort"; @@ -1198,6 +1200,23 @@ Connection connectInternal(Properties propsIn, activeConnectionProperties = (Properties) propsIn.clone(); pooledConnectionParent = pooledConnection; + + String hostNameInCertificate = activeConnectionProperties. + getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString()); + + // hostNameInCertificate property can change when redirection is involved, so maintain this value + // for every instance of SQLServerConnection. + if (null == originalHostNameInCertificate && null != hostNameInCertificate && !hostNameInCertificate.isEmpty()) { + originalHostNameInCertificate = activeConnectionProperties. + getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString()); + } + + if (null != originalHostNameInCertificate && !originalHostNameInCertificate.isEmpty()) { + // if hostNameInCertificate has a legitimate value (and not empty or null), + // reset hostNameInCertificate to the original value every time we connect (or re-connect). + activeConnectionProperties.setProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), + originalHostNameInCertificate); + } String sPropKey; String sPropValue; @@ -3680,7 +3699,6 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException { isRoutedInCurrentAttempt = true; routingInfo = new ServerPortPlaceHolder(routingServerName, routingPortNumber, null, integratedSecurity); - break; // Error on unrecognized, unused ENVCHANGES