R - connecting to SQL Server using using RSQLServer

996 views Asked by At

I want to use RSQLServer instead of RODBC to connect to a database called 'Mkt_DW'. I think my server hostname is my machine DHX number - that's what is returned when I query the hostname in SQL Server 2008 using:

SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser

I then enter the following code into R Studio:

library(RSQLServer)
library(DBI)
driver <- dbDriver("SQLServer")
url <- "DHX32510;Database=Mkt_DW;Trusted_Connection=TRUE;"
conn <- dbConnect(driver, url)

I get the following error:

Error in rJava::.jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", url,  : 
  java.sql.SQLException: Network error IOException: Connection refused: connect

Can anyone tell me what I'm doing wrong?

Thanks,

Neil

1

There are 1 answers

1
czeinerb On

It is because it cannot find the 'sql.yaml' file:

See not from the package author:

"See ?SQLServer. It will look for the YAML file in the following location by default: Sys.getenv("HOME")"

https://github.com/imanuelcostigan/RSQLServer/issues/57