script/console connection works, but Rails app fails with SQL Server


I have an application that connects to a remote SQL Server database using DBI/ODBC. If I run the application via the Rails console, I am able to retrieve data and work with the database just fine. If, however I try to access it via the Web application itself, I get the following error:

DBI::DatabaseError (S1000 (0) [unixODBC][FreeTDS][SQL Server]Unable to connect to data source):     /usr/lib/site_ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect'     /usr/lib/site_ruby/1.8/dbi.rb:424:in `connect'     /usr/lib/site_ruby/1.8/dbi.rb:215:in `connect' ...

Does anyone have any ideas why this would be the case? I've run out of things to try myself, so any help would be appreciated.


To follow up on this one for the googlers, adding this as an initializer to my project seems to fix it.

if ENV['RAILS_ENV'] == 'production'   ENV['ODBCINI'] = "/etc/odbc.ini"   ENV['ODBCSYSINI'] = "/etc"   ENV['FREETDSCONF'] = "/etc/freetds/freetds.conf" end

The problem is that mongrel_cluster is started as root and then spawns mongrels as deploy- but doesn't load environment variables