Search code examples
ruby-on-railssql-servermacosunixodbciodbc

unixodbc and freetds setup on OSX and Rails 2.3.x


I'm trying to set up unixodbc on OSX (10.7.3), but it looks like iODBC is on the way.

My config/database.yml:

development:
  adapter: sqlserver
  encoding: UTF8
  mode: odbc
  username: user
  password: passwd
  dsn: MY_DSN

ruby-obdc is installed and in the Gemfile:

gem 'ruby-odbc', :require => 'odbc_utf8'

/usr/local/etc/freetds.conf:

[MY_SERVER]
host = host.bla.com
port = 1433
tds version = 8.0
client charset = UTF-8

/usr/local/etc/odbc.ini

[MY_DSN]
Driver=/usr/local/lib/libtdsodbc.so
Description=Sql Server Local
Servername=MY_SERVER
Port=1433
Database=my_database

When I run script/console and try to access any model:

Product ODBC::Error: IM002 (0) [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded

It seems iODBC is being used to connect to the database, when I want to use unixodbc. How can I make my rails app use unixodbc instead of iODBC?


Solution

  • Solved by compiling ruby-odbc against Homebrew libraries. This works if you are on OSX:

    gem install ruby-odbc -- --with-odbc-lib=/usr/local/lib