How to connect from ruby to MS Sql Server

Posted by apetrov on Stack Overflow See other posts from Stack Overflow or by apetrov
Published on 2009-05-27T12:27:06Z Indexed on 2010/03/23 21:33 UTC
Read the original article Hit count: 463

Filed under:
|
|
|

Hi Crowd!

I'm trying to connect to the sql server 2005 database from *NIX machine:

I have the following configuration: Linux 64bit

ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux] important gems: dbd-odbc (0.2.4) dbi (0.4.1) active record sql server adapter - as plugin

ruby-odbc 0.9996 (installed without any options.) unixODBC is installed freeTDS is installed

cat /etc/odbcinst.ini

  [FreeTDS]
     Description     = TDS driver (Sybase/MS SQL)
     Driver          = /usr/lib/libtdsodbc.so
     Setup           = /usr/lib/odbc/libtdsS.so
     CPTimeout       =
     CPReuse         =
     FileUsage       = 1

DSN:

DRIVER=FreeTDS;TDS_Version=8.0;SERVER=XXXX;DATABASE=XXX;Port=1433;uid=XXX;pwd=XXXX;"

or

DRIVER=/usr/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=XXXX;DATABASE=XXX;Port=1433;uid=XXX;pwd=XXXX;"

I receive the following error:

>>ActiveRecord::Base.sqlserver_connection({"mode"=>"ODBC", "adapter"=>"sqlserver", "dsn"=>my_dns)
DBI::DatabaseError: IM002 (0) [unixODBC][Driver Manager]Data source name not found, and no default driver specified
    from /usr/lib/ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect'
    from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
    from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
    from /opt/ublip/rails/current/vendor/plugins/activerecord-sqlserver-adapter/lib/active_record/connection_adapters/sqlserver_adapter.rb:47:in `sqlserver_connection'

It looks like ODBC unable to find appropriate ODBC driver, but I have no ideas why.

I had a problem with /usr/lib/libtdsodbc.so which is empty in default debian package free-tds dev, but i solved it with remove broken package and installation from sources.

Will appreciate any thought! Thanks & Regards

Note: I'm albe to connect using the same steps on mac 10.5

© Stack Overflow or respective owner

Related posts about ruby

Related posts about sql-server