从 运行 远程 UNIX 机器上的 R 连接到 SQL 服务器

Connecting to SQL Server from R which is Running on Remote UNIX Machine

我们有一台 UNIX 机器,上面包含 R 引擎并安装了 SQL 服务器 ODBC 驱动程序 11。

我们需要将 R 连接到 SQL 服务器。 SQL 服务器当前在另一台机器上运行,因此我们尝试使用以下代码将 R 连接到 SQL 服务器。

library(RODBC)
dbhandle <- odbcDriverConnect('driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX:1663;')

但是出现错误:

Warning messages: 1: In odbcDriverConnect("driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX:1663;") :

[RODBC] ERROR: state HYT00, code 0, message [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired 2: In odbcDriverConnect("driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX:1663;") :

[RODBC] ERROR: state 08001, code 87, message [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. 3: In odbcDriverConnect("driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX:1663;") :

[RODBC] ERROR: state 08001, code 87, message [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. 4: In odbcDriverConnect("driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX:1663;") : ODBC connection failed

如果我从 UNIX 机器 运行 telnet 到 SQL 服务器,它工作得很好。我的意思是这两台机器之间的连接正常。

我们如何在不使用 DSN 的情况下将 R 连接到 SQL 服务器?

我将服务器和端口之间的分隔符从 : 更改为 , 。它解决了我的问题。

dbhandle <- odbcDriverConnect('driver=ODBC Driver 11 for SQL Server;server=10.XXX.XX.XX,1663;')