Setting up unixodbc and freetds 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 already on the way.

My config / database.yml:

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


ruby-obdc is installed and in Gemfile:

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



host =
port = 1433
tds version = 8.0
client charset = UTF-8



Description=Sql Server Local


When I run script/console

and try to access any model:

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

It seems that iODBC is used to connect to the database when I want to use unixodbc. How do I force my rails app to use unixodbc instead of iODBC?


source to share

3 answers

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




iODBC, maintained and supported by my employer , shipped as part of Mac OS X with Jaguar (10.2.x).

You'd be better off updating iODBC with all the latest fixes (Apple tends to be a little behind them) than moving to UnixODBC. You can also find some benefit in Ruby + ODBC and Ruby-on-Rails that we have posted.

Finally, it is best to keep all ODBC configuration in the default files for Mac OS X -



You can create symlinks from anywhere you want these files, eg. -

ln -s ~/Library/ODBC/odbc.ini ~/.odbc.ini




Using Homebrew. Nessesary to use:

gem install ruby-odbc -- --with-odbc-dir=/usr/local/Cellar/unixodbc/2.3.2


I hadn’t noticed this before, but in Pedro I answered that he had with-odbc-lib

. not sure if this works for his environment, but I needed it to be dir

because I kept checking sql.h ... no error.



All Articles