简体   繁体   English

使用 ODBC ZEFE90A8E604A7C840E88D03D6D 连接到 R 中的 SQL 服务器

[英]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. 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. The credentials are correct, as I can connect through a different client.凭据是正确的,因为我可以通过不同的客户端进行连接。

Following guides on https://support.rstudio.com/hc/en-us/articles/214510788-Setting-up-R-to-connect-to-SQL-Server-以下指南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)

Unfortunately none of the package documentation deals with connecting to a non-default port and just changing the Port parameter doesn't work.不幸的是,package 文档都没有处理连接到非默认端口并且仅更改端口参数不起作用。

When connecting to a non-default port, you will need to add the correct port number both in Port parameter, but ALSO in the Server separated by coma连接到非默认端口时,您需要在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)

This allows you to connect to the server.这允许您连接到服务器。

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

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