简体   繁体   English

R - 使用RSQLServer连接到SQL Server

[英]R - connecting to SQL Server using using RSQLServer

I want to use RSQLServer instead of RODBC to connect to a database called 'Mkt_DW'. 我想使用RSQLServer而不是RODBC连接到名为“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: 我认为我的服务器主机名是我的机器DHX号码 - 这是我在SQL Server 2008中使用以下命令查询主机名时返回的内容:

SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser

I then enter the following code into R Studio: 然后我将以下代码输入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 尼尔

It is because it cannot find the 'sql.yaml' file: 这是因为它无法找到'sql.yaml'文件:

See not from the package author: 请参阅包装作者:

"See ?SQLServer. It will look for the YAML file in the following location by default: Sys.getenv("HOME")" “请参阅?SQLServer。默认情况下,它将在以下位置查找YAML文件:Sys.getenv(”HOME“)”

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM