Search code examples
javasql-serverspring-boothikaricpmssql-jdbc

Springboot 2.0 unable to access SQL Server Database


Please some help with an issue I'm getting on the latest Springboot (2.0.3.RELEASE) I'm getting the following error when trying to access the database. It was working before migrating to the mentioned version of Springboot and Java 10.

Development Enviroment:

-Spring Boot 2.0.3.RELEASE

-JDK / JRE 10 (jdk-10.0.1)

-IDE: Spring Tool Suite 3.9.5.RELEASE

ERROR:

2018-07-19 20:24:37.524 ERROR 12532 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

com.microsoft.sqlserver.jdbc.SQLServerException: 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. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

Caused by: java.io.IOException: SQL Server did not return a response. The connection has been closed. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 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. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 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. ClientConnectionId:33a45785-248c-4b57-ba29-f8802ddd8b25".

I followed the migration guide but without success. I have also tried different configuration found in the web, but nothing addresses this issue.

Is this happening because of the Spring / Java version.

Note the DataSource configuration in the application.properties:

#CURRENT DATASOURCE CONFIG
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:sqlserver://xxx.xxx.x.xx;databaseName=XXX
spring.datasource.hikari.username=user
spring.datasource.hikari.password=password
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = none
spring.jpa.show-sql=true

#FOLLOWING CONFIG ARE JUST FOR REFERENCE. I TRIED THEM AS PER BLOGS 
#spring.datasource.hikari.dataSourceClassName=com.microsoft.sqlserver.jdbc.SQLServerDataSource
#spring.datasource.url=jdbc:sqlserver://XXX.XXX.X.XX;databaseName=XXX
#spring.datasource.url=jdbc:sqlserver://XXX.XXX.X.XX:1433/XXX
#spring.datasource.type=
#spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
#spring.datasource.tomcat.max-active=1
#spring.datasource.username=XXXXXX
#spring.datasource.password=XXXXXX
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDataSource
#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
#spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

I have been looking for a reason this current week. Some advice on a Correct Configuration would be helpful.

Thanks in advance.


Solution

  • It's a MSSQL-JDBC issue. The answer by: Nitin Vavdiya pointed me in the right direction.

    I found the "solution" here: https://github.com/Microsoft/mssql-jdbc/issues/719

    I just modified the java.security file in the JRE Install folder and remove the value: 3DES_EDE_CBC from the jdk.tls.disabledAlgorithms in the file:

    Program Files\Java\"JRE Version"\lib\security

    The following is the exact answer that helped me:

    To improve the strength of SSL/TLS connections, 3DES cipher suites have been disabled in SSL/TLS connections in the JDK via the jdk.tls.disabledAlgorithms Security Property. (http://www.oracle.com/technetwork/java/javase/8u171-relnotes-4308888.html)

    After changing java.security and removing 3DES_EDE_CBC from jdk.certpath.disabledAlgorithms everything works fine. I'm not sure what needs to be changed in SQLServer config to disable 3DES as an SSL scheme though.