![](/img/trans.png)
[英]ODBC/DBI in R will not write to a table with a non-default schema in R
[英]Connecting to SQL Server in R with ODBC package to a non-default port
I'm trying to connect through Rstudio standard ODBC package with driver "ODBC Driver 13 for SQL Server" to a remote SQL Server running on non-default port, but I always get a timeout. 凭据是正确的,因为我可以通过不同的客户端进行连接。
以下指南https://support.rstudio.com/hc/en-us/articles/214510788-Setting-up-R-to-connect-to-SQL-Server-
library(odbc)
con <- dbConnect(odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = "mysqlhost",
Database = "mydbname",
UID = "myuser",
PWD = rstudioapi::askForPassword("Database password")
Port = 21433)
不幸的是,package 文档都没有处理连接到非默认端口并且仅更改端口参数不起作用。
连接到非默认端口时,您需要在Port参数中添加正确的端口号,但也需要在Server中以逗号分隔
library(odbc)
con <- dbConnect(odbc(),
Driver = "ODBC Driver 13 for SQL Server",
Server = "mysqlhost,21433"
Database = "mydbname",
UID = "myuser",
PWD = rstudioapi::askForPassword("Database password")
Port = 21433)
这允许您连接到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.