diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 9fd6545765..153776957a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -2552,13 +2552,18 @@ private void findSocketUsingJavaNIO(InetAddress[] inetAddrs, } } - // if a channel was selected, make the necessary updates + // if a channel was selected, make the necessary updates if (selectedChannel != null) { - // Note that this must be done after selector is closed. Otherwise, - // we would get an illegalBlockingMode exception at run time. - selectedChannel.configureBlocking(true); - selectedSocket = selectedChannel.socket(); + //the selectedChannel has the address that is connected successfully + //convert it to a java.net.Socket object with the address + SocketAddress iadd = selectedChannel.getRemoteAddress(); + selectedSocket = new Socket(); + selectedSocket.connect(iadd); + result = Result.SUCCESS; + + //close the channel since it is not used anymore + selectedChannel.close(); } }