简体   繁体   English

R连接到本地SQL Server

[英]R connecting to Local SQL Server

I cannot connect to my local sql server through Rstudio. 我无法通过Rstudio连接到我的本地SQL Server。 I am able to connect to a SQL Server that my company hosts and I can connect to my local SQL Server through Management Studio. 我能够连接到我公司托管的SQL Server,并且可以通过Management Studio连接到本地SQL Server。 What am I doing wrong? 我究竟做错了什么?

Is there something I need to do to connect locally? 我在本地连接需要做些什么吗? The (LocalDB)\\v11.0 was the exact server name that I connect to my local SQL Server through Management Studio. (LocalDB)\\v11.0是我通过Management Studio连接到本地SQL Server的确切服务器名称。

install.packages("RODBC")

library(RODBC)

dbconnection <- odbcDriverConnect("Driver=SQL Server;Server=(LocalDB)\v11.0;Database=NBA;trusted_connection=yes")                           

The error message I get is the following: 我得到的错误消息如下:

Warning messages: 警告信息:
1: In odbcDriverConnect("Driver=SQL Server;Server=(LocalDB)\\v11.0;Database=NBA;trusted_connection=yes") : 1:在odbcDriverConnect中(“Driver = SQL Server; Server =(LocalDB)\\ v11.0; Database = NBA; trusted_connection = yes”):
[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. [RODBC]错误:状态08001,代码17,消息[Microsoft] [ODBC SQL Server驱动程序] [DBNETLIB] SQL Server不存在或访问被拒绝。

2: In odbcDriverConnect("Driver=SQL Server;Server=(LocalDB)\\v11.0;Database=NBA;trusted_connection=yes") : 2:在odbcDriverConnect中(“Driver = SQL Server; Server =(LocalDB)\\ v11.0; Database = NBA; trusted_connection = yes”):
[RODBC] ERROR: state 01000, code 53, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). [RODBC]错误:状态01000,代码53,消息[Microsoft] [ODBC SQL Server驱动程序] [DBNETLIB] ConnectionOpen(Connect())。

3: In odbcDriverConnect("Driver=SQL Server;Server=(LocalDB)\\v11.0;Database=NBA;trusted_connection=yes") : ODBC connection failed 3:在odbcDriverConnect中(“Driver = SQL Server; Server =(LocalDB)\\ v11.0; Database = NBA; trusted_connection = yes”):ODBC连接失败

try double backslash ... I tried the following and it's working fine: 尝试双反斜杠 ...我尝试了以下,它的工作正常:

library(odbc)
dbconnection <- odbcDriverConnect("Driver=SQL Server;Server=(local)\\SQLSERVER2016;Database=Test_DB;trusted_connection=yes")
data <- sqlFetch(dbconnection, 'dbo.temp_table', colnames=FALSE, rows_at_time=1000)

Thanks. 谢谢。

I had the same error but it was caused by a different problem. 我有同样的错误,但它是由一个不同的问题引起的。 For some reason {SQL Server} did not allow me to connect to Local SQL Server but changing it to {SQL Server Native Client 11.0} worked. 出于某种原因{SQL Server}不允许我连接到本地SQL Server,但将其更改为{SQL Server Native Client 11.0}

library(RODBC)
dbconnection <- odbcDriverConnect("Driver={SQL Server Native Client 11.0};Server= (local)\\SQLSERVER2016;Database=Test_DB;trusted_connection=yes")

Turns out that SQL Server driver known as SQL Server ODBC Driver is an old driver whereas SQL Server Native Client contains both the SQL OLE DB provider and SQL ODBC driver to support native connectivity to SQL Server. 事实证明,称为SQL Server ODBC Driver是旧驱动程序,而SQL Server Native Client包含SQL OLE DB提供程序和SQL ODBC driver以支持与SQL Server的本机连接。

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

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