mssql-jdbc: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Unexpected rethrowing".
Driver version
mssql-jdbc-7.1.2.jre11 mssql-jdbc-7.0.0.jre10 ( i think I got the problem with this one too)
Problem / Question
I’ve been refactoring my database connection code, and I probably have a new non-oblivious problem since but I need some pointers on what is going on in the mssql driver.
I seem to have random problems creating SQL connections that otherwise would work ok. I get the following stacktraces while connecting to a NON-ENCRYPTED sql server 2017 database.
Can someone explain the TDS Prelogin negociations vs SSL vs any other encryption scheme that might explain why I get this exception sometimes ? Or is this wrong exception message ? Is there some SSL going on to login even if we don’t have encrption setup on the sql server side ?
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Unexpected rethrowing".
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2826)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1829)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2391)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2042)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1889)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1120)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:700)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
Caused by: javax.net.ssl.SSLProtocolException: Unexpected rethrowing
at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
at java.base/sun.security.ssl.SSLTransport.decode(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.decode(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1756)
... 41 more
Caused by: java.io.IOException: SQL Server returned an incomplete response. The connection has been closed. ClientConnectionId:b9ef7c65-28e5-4858-9cc1-642eaa2725d1
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:786)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:836)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:829)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:999)
at com.microsoft.sqlserver.jdbc@7.1.2.jre11-preview/com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:989)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source)
at java.base/sun.security.ssl.SSLSocketInputRecord.decode(Unknown Source)
... 46 more
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 39 (10 by maintainers)
@peterbae Its the most simple one:
by rapidly reloading data in my app I just got the exception again (even with encrypt=false which I just added).
Could you use connection property
sslProtocol=TLSv1to force the driver to use TLS 1.0 and let me know if you are still seeing failures? Your connection string would becomejdbc:sqlserver://WKS-DEV-23;encrypt=false;user=user;password=xxxxxx;applicationName=xxx;databaseName=XXXXX;sslProtocol=TLSv1;This is an older thread but I wanted to leave this here in case it helps somebody scouring the Internet…
I was getting this error in an AWS Lambda function and found it was caused by giving the function too little memory. I bumped it up from 128MB to 512MB (probably overkill) and it works now. “The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption” was pretty misleading but it turned out to be too little memory.
We fixed this issue by enforcing
sslProtocol=TLSv1.2;in our database connection string.Currently I am getting this issue
com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1509)
I am trying to connect to mssql server from java dynamic web project.Any help is appreciable
Hi @muhammedOzbilici , Please go through the closed issues, there might already be a solution provided for your problem.
But, is it not related to SSL ? If it’s not then, which configuration I have to check on Database side ?
Hi @martinm1000 ,
Thank you for testing the build. I created a PR, please feel free to review it.
Great, now we confirmed that you are seeing the failures because of intermittent TLS1.2 issues.
Please take a look at this article, which explains the cause of the issue (changes to Windows ciphers) and also possible resolution/workarounds.
I would also like to explain why the driver is unable to retry when there is a logic implemented for this. Intermittent TLS1.2 issue is “guessed” by the driver based on the error message from the server. See this line. For some reason, your JDK version wraps the actual and expected exception message
SQL Server returned an incomplete response. The connection has been closed.intoUnexpected rethrowing. Below is the stack trace of my application with Oracle JDK 11.0.1+13.Notice how
Caused by: javax.net.ssl.SSLProtocolException: SQL Server returned an incomplete response. The connection has been closed.is different from yours, hence the driver throws the exception without retrying.Please let me know if you have any other questions.