[英]Error connecting to sql server with docker, rbase, and RODBC
I'm trying to access a SQL Server on a local intranet with R, where R is loaded in a docker file with R-base. I'm trying to access a SQL Server on a local intranet with R, where R is loaded in a docker file with R-base.
On my desktop, I create a ODBC driver and it recognizes my windows credentials with the following:在我的桌面上,我创建了一个 ODBC 驱动程序,它通过以下内容识别我的 windows 凭据:
odbcDriverConnect('driver={SQL Server};server=<serverName>;database=<dbName>;trusted_connection=yes')
Using R-base, after a lot of trial and error I was able to get RODBC installed, but I have no idea how to connect to this server.使用 R-base,经过大量试验和错误后,我能够安装 RODBC,但我不知道如何连接到该服务器。
Warning messages:
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
The DockerFile, which was built with a lot of trial and error. DockerFile,经过大量试验和错误构建。 I'm sure much of it is redundant.
我敢肯定其中大部分是多余的。 Also I exposed ports which I found doing some research but I have no idea if they are needed to be exposed.
我还暴露了一些我发现做一些研究的端口,但我不知道是否需要暴露它们。
FROM openanalytics/r-base
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
libcairo2-dev \
libxt-dev \
libcurl4-gnutls-dev \
libssl-dev \
libssh2-1-dev \
libssl1.0.0
# RODBC
RUN apt-get update && \
apt-get install -y --no-install-recommends \
unixodbc \
unixodbc-dev \
unixodbc \
unixodbc-dev \
r-cran-rodbc \
apt-transport-https \
libssl-dev \
libsasl2-dev \
openssl \
curl \
unixodbc \
gnupg \
libc6 libc6-dev libc6-dbg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#RUN curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev mssql-tools
EXPOSE 3838
EXPOSE 8787
Once I build the file, I enter R studio and use install.packages("RODBC")
构建文件后,我进入 R 工作室并使用
install.packages("RODBC")
How can I connect to the SQL server from the docker file?如何从 docker 文件连接到 SQL 服务器?
----------Update - - - - - 更新
after creating a docker container with Ubuntu, I found that I was not able to ping the server name.在使用 Ubuntu 创建 docker 容器后,我发现我无法 ping 服务器名称。 I was however, able to ping the server ip address.
但是,我能够 ping 服务器 ip 地址。
I modified the search string to ping the ip address, and changed the driver, as follows:我修改了搜索字符串ping ip地址,并更改了驱动,如下:
odbcDriverConnect('driver={ODBC Driver 17 for SQL Server};server=<serverName>;database=<dbName>;trusted_connection=yes')
This still did not work.这仍然没有奏效。
I could not figure out how to connect to the database with the Windows credentials of the docker host inside of the docker virtual machine.我无法弄清楚如何使用 docker 虚拟机内的 docker 主机的 Windows 凭据连接到数据库。
I had to make a username and password for the database and connect with that.我必须为数据库创建一个用户名和密码并与之连接。
I think if you change your driver to FreeTDS this will work.我认为如果您将驱动程序更改为 FreeTDS,这将起作用。 R doesn't support Sql Server drivers unless its a pro plan.
R 不支持 Sql 服务器驱动程序,除非它是专业计划。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.