0
votes

I use

  • JTDS version: jtds-1.3.1
  • MS SQL JDBC version: mssql-jdbc-8.4.0.jre8 even mssql-jdbc-9.2.0.jre8
  • Java 8 Update 251

For simplicity, the code will the same as:

Android studio can't connect to database in Azure sql server

I have a problem to connect to SQL Server or Azure SQL.

I want to connect with this syntax:

val connectionString = "jdbc:jtds:sqlserver://192.168.xx.xx:1433;databaseName=myData;user=x1;password=p1;encrypt=true;trustServerCertificate=true;"

With this JTDS connection string, I can connect to my SQL Server DB on localhost, but with MS-JDBC, I failed to connect.

val connectionString = "jdbc:sqlserver://192.168.xx.xx:1433;databaseName=myData;user=x1;password=p1;encrypt=true;trustServerCertificate=true;"

I get the following errors:

com.microsoft.sqlserver.jdbc.SQLServerException: The Driver could not establish a secured connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Socket is closed". ClientConnectionId: xxxxxxxxxxxxxxxxx

An interesting thing happens when I connect with JTDS version to SQL Azure with the command:

jdbc:jtds:sqlserver://xxxxx.database.windows.net:1433;database=xxxxx;user=username;password=password;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;

I failed to connect to SQL Azure with the following errors

java.sql.SQLException: Reason: Login Failed due to client TLS Version being less than minimal TLS Version allowed by the server

I already tried:

  1. SSLProtocol=TLSv1.2 (TLS, TLSv1.0, TLSv1.1) => none work
  2. ssl=require

Is it a bug with JTDS, a bug with JDBC, o isr my connection string invalid? I can connect to SQL Azure with my dotnet apps (C#).

1
docs.microsoft.com/en-us/azure/azure-sql/managed-instance/… Can you try changing TLS version on azure?sonny
already use TLS 1.2 version on SQL Azure. and another instance use TLS 1.0, but NONE WORKSChandra Arifin
i can connect with the same connection string to sql azure, BUT DON'T CLICK the Minimum TLS Version. if you already CHANGE the minimum TLS version (1.0, 1.1 or 1.2) and the connection will FAIL. hope this help someone.Chandra Arifin
@ChandraArifin Not clear on what you mean, do you mean you can connect to SQL Azure with jTDS? What changes are needed? Thanks.user2552742
yeah, i can connect to SQL Azure with jTDS. nothing changes. just make sure when you create SQL Azure for the first time, DONT CHOOSE TLS VERSION, just let it be. if you already choose one of TLS, then you can't connect with jTDS because it is already encrypted.Chandra Arifin

1 Answers

0
votes

I just fixed this in an Azure Managed Instance using the PowerShell script below:

Set-AzSqlInstance -Name 'InstanceName' -ResourceGroupName 'ResourceGroupName' -MinimalTlsVersion "None" -force