Trying to connect to an ODBC server using RODBC in ubuntu

你说的曾经没有我的故事 提交于 2019-11-29 20:18:47

问题


I am getting the error:

 [RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found
 2: In odbcDriverConnect("driver={SQL Server};server=*******;database=****;trusted_connection=true") :
 ODBC connection failed

Can anyone provide detailed instructions on installing the driver for ODBC in order for it to work with RODBC?

Note: I am trying to connect to an MSSQL Server


回答1:


Here at my job, we use Centos 5.8. When I need to connect to our MS-SQL servers, I use FreeTDS drivers. I talk a bit more about it here: https://stackoverflow.com/a/10196098/1332389, including the packages and dependencies that I installed.

A sample connection string might look like this:

data_odbc <- odbcDriverConnect(connection="Driver=FreeTDS;
                                           Server=dataserver1\\instancename(default: master);
                                           Port=1433;        
                                           Database=database_01;
                                           Uid=data_mgmt;
                                           Pwd=placeholder")

We configured our odbcinst.ini file (in /etc/) to say:

# FreeTDS Drivers
# Manual setup, used for MS SQL
[FreeTDS]
Description     = FreeTDS for MSSQL
# 32 bit
Driver          = /usr/lib/libtdsodbc.so
Setup           = /usr/lib/libtdsS.so
# 64 bit
Driver64        = /usr/lib64/libtdsodbc.so
Setup64         = /usr/lib64/libtdsS.so
FileUsage = 1

I've had no issues since getting it set up. Hope this helps - I can try and answer if you have more questions.




回答2:


I had similar problem using remote R session on Linux, with RJServer, connecting to it from StatET under Eclipse. The error looked like this:

[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib '/usr/local/easysoft/sqlserver/lib/libessqlsrv.so' : file not found

The difficulty of solving this problem was that the error message is misleading: the file shown in the message is perfectly visible (I could test it). The "secret" is that "file not found" refers to another dependent library.

Bottom line: I added few elements to the LD_LIBRARY_PATH used in the remote session, in my case it was: /usr/local/easysoft/unixODBC/lib:/usr/local/easysoft/lib

To figure out what you need to add, you should see what is missing. Use "ldd" command on the library in question.



来源:https://stackoverflow.com/questions/11084173/trying-to-connect-to-an-odbc-server-using-rodbc-in-ubuntu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!