0

I have been using RODBC to do all sort of sql queries, but I ended up having to deal with a query that happens to take a painfully amount of time compared to when I run the query in SQL Server.

I found in this post that RJDBC has a better performace, so I decided to try it out.

I ended up intalling Java (both jre and jdk), setted up the Paths and the Drivers of JDBC.

I have no problem getting the driver I guess, since I got no error.

drv <- JDBC(classPath = "C:\\Program Files\\Microsoft JDBC DRIVER 11.2 for SQL Server\\sqljdbc_11.2\\enu\\mssql-jdbc-11.2.0.jre8.jar")

But when I try to create the connection I get the following error

conn <- dbConnect(drv, "jdbc:sqlserver://192.168.7.303", "my_user", "my_password")

Error in dbConnect(drv, "jdbc:sqlserver://192.168.7.303", "my_user", : Unable to connect JDBC to jdbc:sqlserver://192.168.7.303 JDBC ERROR: The driver couldn't establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target". ClientConnectionId:8902e2fd-d90e-47c8-8aed-7ea373c9245d

Is there a solution to this problem?

jarlh
  • 42,561
  • 8
  • 45
  • 63
Alejo
  • 315
  • 1
  • 10
  • Have you tried adding `TrustServerCertificate=false;` to your connection properties? JDBC 10.2 introduced a breaking change, making `Encrypt=true;` a default parameter (previously it was `Encrypt=false;`), causing encrypted connections to SQL Server instances. This is problematic because Microsoft SQL Server installs with self-signed (read: untrusted) certificates by default, thus causing the error message that you are seeing. Ref: [JDBC Driver 10.2 for SQL Server Released](https://techcommunity.microsoft.com/t5/sql-server-blog/jdbc-driver-10-2-for-sql-server-released/ba-p/3100754). – AlwaysLearning Aug 26 '22 at 23:44
  • Use the DNS name rather than the IP address. Do you actually have SQL Server set up with a valid SSL certificate? – Charlieface Aug 28 '22 at 00:30
  • AlwaysLearning: do you mean: `dbConnect(drv, "jdbc:sqlserver://192.168.7.303; TrustServerCertificate=false;", "my_user", "my_password")` ? – Alejo Aug 29 '22 at 17:22

0 Answers0