Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to connect to an ODBC server using RODBC in ubuntu

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

like image 617
Nick Trileski Avatar asked Jun 18 '12 13:06

Nick Trileski


People also ask

How do I connect to a SQL Server Remote using ODBC?

Right-click the server and select Properties. Go to Security and select SQL Server and Windows Authentication Mode. Go to Connection and select Allow remote connection to this server. Restart the SQL server.

Which function is used to connect to an ODBC?

SQLConnect() allows you to connect to the database using connection attributes stored in the ODBC Data Source Name (DSN) definition.


2 Answers

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.

like image 176
TARehman Avatar answered Sep 28 '22 03:09

TARehman


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.

like image 38
Leonid Avatar answered Sep 28 '22 05:09

Leonid