I am trying to connect my spring boot application with sql server database but it throwing an Exception and saying :
020-08-18 16:58:11.580 ERROR 14800 --- [ main] 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. .
However I am able to connect with oracle database the issue arises when I try to connect with sql server.
here is the application.properties file
spring.datasource.url=jdbc:sqlserver://192.168.*.*\\DB2008;databaseName=mydbname
spring.datasource.username=myuser
spring.datasource.password=mypassword
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
here is the detailed error:
2020-08-18 16:58:11.580 ERROR 14800 --- [ main] 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:37aa16bd-92f0-4af0-a090-06f2349cb51a".
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2924) ~[mssql-jdbc-7.4.0.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1881) ~[mssql-jdbc-7.4.0.jre8.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2484) ~[mssql-jdbc-7.4.0.jre8.jar:na]
In this case can you can try the following steps.
Make sure that your SQL server is running locally(Are you trying to connect to a remove SQL server?)
Alternatively, In your URL after your Data base name use this statement jdbc:mysql://IP:3306/someDatabase?autoReconnect=true&useSSL=false
I have resolved this issue by following the below steps:
Edit C:\Program Files\Java\jdk1.8.0_251\jre\lib\security\java.security
find the below variable it will have multiple comma separated values remove one value which I have mentioned below:
Find: jdk.tls.disabledAlgorithms=
Remove: 3DES_EDE_CBC
This should fix it!
Related
I'm trying to log in to Azure Sql Server using my active directory credentials and getting an error as follows.
JDBC : mssql-jdbc-8.4.1.jar
ADAL4J : 1.2.0
Connection String : jdbc:sqlserver://"${address}":"${port}";integratedSecurity="${int-security}";authentication=ActiveDirectoryPassword"
Error: Cannot open server "a.com.au" requested by the login. The login failed
Note : HikariCP connection pool is used in the code.
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=wstapp
#spring.datasource.password=wstapp#test
#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.
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.
I am connecting HANA DB via ngdbc.jar. Connection is made properly but after running query 3-4 times connection to HANA DB is lost. When I restart my JAVA server again it works for 3-4 times. Can anyone help?
Error Msg-
WARN [org.hibernate.util.JDBCExceptionReporter] (http--0.0.0.0-8080-6) SQL Error: -708, SQLState: 08006
ERROR [org.hibernate.util.JDBCExceptionReporter] (http--0.0.0.0-8080-6) Data receive failed [Connection reset].
INFO [com.ultimatix.controller.MetricsController] (http--0.0.0.0-8080-6) context setMonthFreezeDateorg.hibernate.exception.JDBCConnectionException: could not execute query
ERROR [org.hibernate.transaction.JDBCTransaction] (http--0.0.0.0-8080-6) JDBC rollback failed: com.sap.db.jdbc.exceptions.jdbc40.SQLNonTransientConnectionException: Connection to database server lost; check server and network status [System error: Socket closed]
I can see you are using Hibernate based on your log.
Can you elaborate a little bit on your stack?
As #RC said, you should consider connection pooling instead of opening direct connections if this is what you are doing in your "JAVA" server.
May be your are keeping the connection open for too long and it times out.
These are all guesses, until you can share any logs or sample code.
One more thing, related to the ngjdbc driver only, there is a "reconnect" connection property which by default is set to false.
Regards
I have app in SpringBoot with JPA.
When I lost connection my app send me error:
WARN 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17002, SQLState: 08006
ERROR 6812 --- [io-8080-exec-42] o.h.engine.jdbc.spi.SqlExceptionHelper : IO Error: Socket read timed
out
After estabilishin connection I can't use my EntityManager, because I get:
WARN 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17008, SQLState: 08003
ERROR 6812 --- [io-8080-exec-50] o.h.engine.jdbc.spi.SqlExceptionHelper : Closed Connection
My connection properties:
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#...:..:..
spring.datasource.username=...
spring.datasource.password=...
spring.datasource.test-on-borrow=true
spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1;
What should I do to reconnect that DB connection?
Try adding an external connection pool, such as HikariCP, since Spring Boot will automatically detect and use it:
If HikariCP is available we will use it.
If your using a JDBC4 Driver, the connection pool will validate the connection before handing it to you. If you are using an older driver you need to set this property:
connectionTestQuery
If your driver supports JDBC4 we strongly recommend not setting this
property. This is for "legacy" databases that do not support the JDBC4
Connection.isValid() API. This is the query that will be executed just
before a connection is given to you from the pool to validate that the
connection to the database is still alive. Again, try running the pool
without this property, HikariCP will log an error if your driver is
not JDBC4 compliant to let you know. Default: none
I am facing this problem.
Stackstrace
2014-09-22 16:50:35,292 [main] WARN org.hibernate.cfg.SettingsFactory
- Could not obtain connection metadata org.apache.commons.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (IO Error: Connection reset) at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
can any one please let me know the cause of this , oracle version is 11g
Your stack trace specifies that you are unable to connect to your database.
Make sure that your database server is listening on the correct port (1521 default).
Check your firewall or any setting that prevents you from accessing your database server
Check your dataSource settings for any errors.
If your database is an external one, make sure that the listener.ora is configured correctly.