3
votes

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?

3

3 Answers

2
votes

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
1
votes

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

You'll be better off updating iODBC with all the latest patches (Apple tends to be a bit behind on these), than shifting to UnixODBC. You may also find some benefit in the Ruby+ODBC and Ruby-on-Rails docs we've published.

Last, it's best to keep all your ODBC configuration in the default file locations for Mac OS X --

/Library/ODBC/odbc.ini
/Library/ODBC/odbcinst.ini
/Users/*/Library/ODBC/odbc.ini
/Users/*/Library/ODBC/odbcinst.ini

You can create symlinks from anywhere else you may want to have these files, e.g. --

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

Using Homebrew. Needed to use:

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

I didn't notice this earlier but in Pedro's answer he has with-odbc-lib. not sure if that works for his environment, but i needed this to be dir, because i kept getting a checking for sql.h... no error.