在 R Studio 服务器中找不到 ODBC SQL 服务器

ODBC SQL server not found in R Studio Server

我正在尝试将 Azure SQL 实例连接到我在 Ubuntu 上提供服务的 R Studio 服务器。

library(DBI)

library(odbc)

con_string <- paste(c('DRIVER', "PORT", "SERVER", "DATABASE", "UID", "PWD"),
                    c('{ODBC Driver 17 for SQL Server}', 1433,
                      "mydatabase.database.secure.windows.net", "DB1",
                      "me", "foo"),
                    sep = "=", collapse = ";")


con <- DBI::dbConnect(odbc::odbc(), .connection_string = con_string)

我得到的错误:

Error: nanodbc/nanodbc.cpp:950: 01000: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found 

我已经尝试了所有其他驱动程序:

{ODBC Driver 17 for SQL Server}
{ODBC Driver 13 for SQL Server}

我无法连接。我在其他环境中使用过 pyodbc 并且能够使用相同的字符串进行连接。

我确认已安装 ODBC 库:

ubuntu@ip-1-2-3-4:~$ sudo apt-get install unixodbc unixodbc-dev --install-suggests
Reading package lists... Done
Building dependency tree       
Reading state information... Done
unixodbc is already the newest version (2.3.1-4.1).
unixodbc-dev is already the newest version (2.3.1-4.1).
The following packages were automatically installed and are no longer required:
  linux-aws-headers-4.4.0-1048 linux-aws-headers-4.4.0-1049 linux-headers-4.4.0-1048-aws linux-headers-4.4.0-1049-aws linux-image-4.4.0-1048-aws
  linux-image-4.4.0-1049-aws
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 107 not upgraded

。看来驱动程序在我的 R 环境中不可用,或者我称它为错误的东西。 This is the R Server docs that I'm reading

问题并非来自 unix-odbc 库。 确实如您所见:

[unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found

2种解决方法是尝试:

  • 问题是没有找到驱动。这可能是因为您的驱动程序未正确安装在您的计算机中。确认您遵循了安装步骤。

  • 也可能是由于 C++ 应用程序编译时缺少 -Wl,-rpath,<Link to your gcc driver library> 选项造成的。但由于 R 语言 是用 C 语言编写的,这应该不会影响您。