diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 87d408dac..2dfcdfb0c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -1859,7 +1859,7 @@ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnectio if (0 == connectRetryCount) { // connection retry disabled throw e; - } else if (++connectRetryAttempt > connectRetryCount) { + } else if (connectRetryAttempt++ > connectRetryCount) { // maximum connection retry count reached if (connectionlogger.isLoggable(Level.FINE)) { connectionlogger.fine("Connection failed. Maximum connection retry count " @@ -3249,7 +3249,6 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu || (SQLServerException.ERROR_SOCKET_TIMEOUT == driverErrorCode // socket timeout && (!isDBMirroring || attemptNumber > 0)) // If mirroring, only close after failover has been tried (attempt >= 1) || timerHasExpired(timerExpire) - || (state.equals(State.CONNECTED) && !isDBMirroring) // for non-dbmirroring cases, do not retry after tcp socket connection succeeds ) { // close the connection and throw the error back @@ -6329,9 +6328,10 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ serverName = currentConnectPlaceHolder.getFullServerName(); } else { serverName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.SERVER_NAME.toString()); - if (null != activeConnectionProperties.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) { - serverName += "\\" + - activeConnectionProperties.getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString()); + if (null != activeConnectionProperties + .getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString())) { + serverName += "\\" + activeConnectionProperties + .getProperty(SQLServerDriverStringProperty.INSTANCE_NAME.toString()); } } @@ -7390,7 +7390,8 @@ void endRequestInternal() throws SQLException { String replaceParameterMarkers(String sqlSrc, int[] paramPositions, Parameter[] params, boolean isReturnValueSyntax) { final int MAX_PARAM_NAME_LEN = 6; - char[] sqlDst = new char[sqlSrc.length() + (params.length * (MAX_PARAM_NAME_LEN + OUT.length)) + (params.length * 2)]; + char[] sqlDst = new char[sqlSrc.length() + (params.length * (MAX_PARAM_NAME_LEN + OUT.length)) + + (params.length * 2)]; int dstBegin = 0; int srcBegin = 0; int nParam = 0; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java index 690a7e3fe..313089099 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java @@ -478,39 +478,6 @@ public void testConnectCountInLoginAndCorrectRetryCount() { } } - /** - * Tests whether connectRetryCount and connectRetryInterval are properly respected in the login loop. As well, tests - * that connection is retried the proper number of times. This is for cases with zero retries. - */ - @Test - public void testConnectCountInLoginAndCorrectRetryCountWithZeroRetry() { - long timerStart = 0; - - int connectRetryCount = 0; - int connectRetryInterval = 60; - int longLoginTimeout = loginTimeOutInSeconds * 3; // 90 seconds - - try { - SQLServerDataSource ds = new SQLServerDataSource(); - ds.setURL(connectionString); - ds.setLoginTimeout(longLoginTimeout); - ds.setConnectRetryCount(connectRetryCount); - ds.setConnectRetryInterval(connectRetryInterval); - ds.setDatabaseName(RandomUtil.getIdentifier("DataBase")); - timerStart = System.currentTimeMillis(); - - try (Connection con = ds.getConnection()) { - assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); - } - } catch (Exception e) { - assertTrue(e.getMessage().contains(TestResource.getResource("R_cannotOpenDatabase")), e.getMessage()); - long totalTime = System.currentTimeMillis() - timerStart; - - // Maximum is unknown, but is needs to be less than longLoginTimeout or else this is an issue. - assertTrue(totalTime < (longLoginTimeout * 1000L), TestResource.getResource("R_executionTooLong")); - } - } - @Test @Tag(Constants.xAzureSQLDW) @Tag(Constants.xAzureSQLDB)