我们已在 Azure Linux VM (Ubuntu) 上配置并安装了 RStudio Pro 2023.12.1 (Posit Workbench) 软件,现在通过 chrome 登录该软件后。
我想连接到我们的 Azure 数据仓库服务,其中使用下面的代码提供了我们的数据集和表。
library(odbc)
con <- dbConnect(odbc(),
Driver = "ODBC Driver 17 for SQL Server",
Server = "sqldwserver.database.windows.net",
Database = "sqldwdb",
UID = "USER",
PWD = rstudioapi::askForPassword("Database password"),
Port = 1433)
但是运行代码后我收到如下错误,
dbConnect 中的错误(odbc(),驱动程序 =“适用于 SQL Server 的 ODBC 驱动程序 17”, 服务器=“ucbsqldwserver.database.windows.net”,:找不到 函数“dbConnect”
当我尝试安装odbc软件包时,遇到以下错误。根据此错误,我了解到 odbc 软件包未安装在 Linux 虚拟机上,这导致我无法建立连接。
我能够在安装了 RStudio 桌面免费版本的 Windows Azure VM 上运行上述代码,但在安装在 Linux VM 上的 Post Workbench Web 版本上遇到此错误。
由于我对 R 和 Linux 操作系统的了解有限,您能帮我修复此错误吗?
odbc 包安装错误 --
install.packages("odbc")
Installing package into ‘/home/rajP/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/odbc_1.5.0.tar.gz'
Content type 'application/x-gzip' length 299106 bytes (292 KB)
downloaded 292 KB
installing source package ‘odbc’ ...
** package ‘odbc’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
PKG_CFLAGS=
PKG_LIBS=-lodbc
:1:10: fatal error: sql.h: No such file or directory
compilation terminated.
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because odbc was not found. Try installing:
deb: unixodbc-dev (Debian, Ubuntu, etc)
rpm: unixODBC-devel (Fedora, CentOS, RHEL)
csw: unixodbc_dev (Solaris)
pacman: unixodbc (Archlinux, Manjaro, etc)
brew: unixodbc (Mac OSX)
To use a custom odbc set INCLUDE_DIR and LIB_DIR and PKG_LIBS manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=... PKG_LIBS=...'
ERROR: configuration failed for package ‘odbc’
removing ‘/home/rajP/R/x86_64-pc-linux-gnu-library/3.6/odbc’
Warning in install.packages :
installation of package ‘odbc’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpMHrTw7/downloaded_packages’
看起来您可能需要安装并加载 DBI 包,它提供了通用的
dbConnect()
(odbc 为其提供了方法)!
所以,替换:
library(odbc)
与:
library(odbc)
library(DBI)