I have an SQL Server 2014 updated to the latest fixpack (12.0.5207). In the environment, the only protocol enabled is TLS1.2 (the registry keys has been set for the purpose). I can connect to the SQL server using the SA account both locally and remotely using Management Studio.
However when I try establishing a connection to the SQL server using java code and the JDBC driver sqljdbc42.jar the following exception is thrown: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection has been closed.
The java code is the following: public static void main(String[] args) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { System.out.println( e.toString() ); } String connectionUrl = "jdbc:sqlserver://localhost:1433;" + "databaseName=TRCDB;user=sa;password=**********;"; try { Connection con = DriverManager.getConnection(connectionUrl); } catch (SQLException e) { System.out.println( e.toString() ); } }
When the JVM is launched the following option are passed: -Djavax.net.debug=all -Djdk.tls.client.protocols="TLSv1.2" -Dhttps.protocols="TLSv1.2"
So although only TLSv1.2 is enabled the "Client Hello" is done using TLSv1: jdk.tls.client.protocols is defined as TLSv1.2 SSLv3 protocol was requested but was not enabled SUPPORTED: [TLSv1, TLSv1.1, TLSv1.2] SERVER_DEFAULT: [TLSv1, TLSv1.1, TLSv1.2] CLIENT_DEFAULT: [TLSv1.2] ... *** ClientHello, TLSv1 ... main, WRITE: TLSv1 Handshake ... main, called close() main, called closeInternal(true) main, SEND TLSv1.2 ALERT: warning, description = close_notify main, WRITE: TLSv1.2 Alert, length = 2
Is it the TLS version the root cause of the problem? How can I force TLSv1.2?
本文介绍了一个使用 Java JDBC 驱动连接 SQL Server 2014 时遇到的问题,当仅启用 TLS 1.2 协议时,连接失败并抛出安全连接异常。文中提供了使用的 Java 代码示例及 JVM 启动参数。

1629

被折叠的 条评论
为什么被折叠?



