首页 > 解决方案 > 在 R Studio Server 中找不到 ODBC SQL 服务器

问题描述

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

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 环境中不可用,或者我称它为错误的东西。这是我正在阅读的 R Server 文档

标签: odbcrstudio-serverazure-sql-serverr-dbi

解决方案


问题不是来自unix-odbc库。确实如你所见:

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

2 解决方案是尝试:

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

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


推荐阅读