2

I am trying to access the database using RJDBC from RStudio but I am getting the following error.

I am unable to understand my mistake. I will be appreciated if somebody help me on this.

Code:

install.packages("RJDBC")
library(RJDBC)

drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver","c://sqljdbc42.jar")
conn <- dbConnect(drv, "jdbc:sqlserver://191.169.120.213:1433", "username", "password")

Output:

Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1],  : 
  com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.120.213, port 1433 has failed. Error: "Connection timed out: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

Note: I do not have any firewall related issue.

Bhaskar Das
  • 652
  • 1
  • 9
  • 28
  • Have you checked to see whether R thinks you're online? Try installing the `pingr` library and then `is_online()` will tell you. – mysteRious Mar 20 '18 at 18:19
  • Also this: `ping_port("191.169.120.213", port=1433)` – mysteRious Mar 20 '18 at 18:21
  • Result: `[1] NA NA NA` @mysteRious – Bhaskar Das Mar 20 '18 at 18:33
  • The response should be three timings, so NA means there was no response. Can you connect to the database directly? If you have any network people around, have them check and make sure the db is on that IP and port and that it's active. – mysteRious Mar 20 '18 at 19:37
  • I get the same error. I can access the server with DBeaver SQL client and I can ping the server. What else could it be? – Giacomo Apr 19 '21 at 09:52

1 Answers1

0

I had the same error and I realised my company was using NTLM Authentication.

I was able to connect specifying additional proprieties in the connection string, as below:

conn <- dbConnect(drv, "jdbc:sqlserver://191.169.120.213:1433;databaseName=db_name;integratedSecurity=true;authenticationScheme=NTLM", "username", "password")

This is the link to the Microsoft documentation.

Giacomo
  • 1,796
  • 1
  • 24
  • 35