![](/img/trans.png)
[英]How to connect via R to MS SQL database requiring integrated active directory authentication using odbc and DBI packages?
[英]How to connect to MS SQL Server using ODBC and DBI in R
我无法从 R 连接到我的 MS SQL 服务器。
我相信我使用了正确的驱动程序,我检查了我列出的驱动程序并选择了我在 DBeaver 中使用的相同驱动程序来连接到同一个数据库:
odbcListDrivers() %>% filter(name %like% "SQL Server" & !name %like% "Teradata")
我的连接字符串如下所示:
db_conn <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "Server_address",
Database = "Database_Name",
UID = "myName",
PWD = "myPWd",
Trusted_Connection = "True",
Port = 1433,
ApplicationIntent = "ReadOnly"
)
我收到以下错误:
Error: nanodbc/nanodbc.cpp:1021: 01S00: [Microsoft][ODBC SQL Server Driver][SQL Server]The target database ('Database_Name') is in an availability group and is currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online. [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute
我可以使用 DBeaver 连接到同一个数据库并指定连接具有 applicationIntent = readonly
是否需要包含其他一些连接字符串属性才能建立连接?
原来我使用了正确的连接字符串属性,但服务器在集群模式下运行,因此我需要将 append 'CLS' 设置为我的数据库名称。
我的最终连接字符串如下所示:
db_conn <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "SomeDBcls.xx.yy.zz.com",
Database = "NameOfSchema",
UID = "TheGoat",
PWD = rstudioapi::askForPassword("Database password"),
Trusted_Connection = "Yes",
Port = 1433,
applicationIntent = "readonly"
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.