1

Created an Azure SQL server machine and I am able to rdp as well as connect via the local SQL Server Mgt Studio client.

However I cannot connect to the same instance via Java code using the connection string further below.

  • I am using the latest JDBC Driver (Microsoft JDBC Driver 7.4)
  • I am using SQL Server 2017 Express
  • I am able to connect manually via SQL Server Mgt Studio client on local machine

Here is the error message:

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". ClientConnectionId:xxxxxxxxxxxxxxxxxx

Here is the connection string:

jdbc:sqlserver://Server=nn.nnn.nnn.nnn;Integrated Security=false;User ID=myusername;Password=mypassword

Thanks for your help!

2 Answers 2

1

I got this to work by changing in the connection string:

encrypt=true

into

encrypt=false

Not sure this is the best solution but at least I can carry on developement.

Sign up to request clarification or add additional context in comments.

3 Comments

@LeonYue I dont believe this is the best solution. This is why I have not marked it as the accepted solution.
unfortunately the project is abandoned as the new direction is Python
If you are working on your localhost is fine - else do the right thing with the cert.
0

It seems to be caused by the driver not finding a certificate that it trusts. If you do have a relevant certificate installed and are working on your localhost (meaning that it's probably self-signed and therefore wouldn't be trusted otherwise), try adding this to the end of your connection string: trustServerCertificate=true

If it's a different machine you're working on, you may need to take a look at the validity of the certificate that it should be using.

Microsoft also now has more information about SSL connections to SQL Server here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.