Satya's blog - Rails and Sybase
I just spent 4 hours trying to get Ruby on Rails to talk to Sybase. This is Rails 2.1-ish on Ubuntu 9.04, installed from the debian system (not gems). It wouldn't work. No matter what. I tried installing the sybase adapter: gem install activerecord-sybase-adapter -s http://gems.rubyonrails.org Nope. And that's after freetds was already installed. It wasn't a freetds error -- it kept yelling about activerecord versions, just like odbc below. I tried the odbc driver: gem install activerecord-odbc-adapter It kept pulling in activerecord 2.3.2 (remember, I have 2.1.0 from Ubuntu's debs). And then borking on mismatched versions. Note that those two gem commands work. The breakage happens when you try to actually access something, such as User.find(:first) from script/console: Gem::Exception: can't activate activerecord (>= 2.0.2, runtime), already activated activerecord-2.1.0 This is because those gems pull in a gem version of activerecord, which is 2.3.2. The apt-get version is 2.1.0. So I ripped out rails and installed it as a gem: sudo apt-get remove rails sudo gem install -V rails activerecord-odbc-adapter odbc-rails # (takes a long time) sudo apt-get autoremove sudo apt-get install irb libdbd-odbc-ruby (You'll need ruby-dev if you want to install a gem like 'mysql', which I do. What, you think Sybase is my database of choice? Hah! Oh wait, the mysql gem won't install. WTF? Oh, ok, I can apt-get install libdbd-mysql-ruby, and that gets me a find() on a mysql database. If that hadn't worked, I'd be yelling.) I stuck this in ~/odbc and ran "odbcinst -i -s -d ~/odbc" (I have tdsodbc and unixodbc, dunno how much of that is required): [d] Description = d server, name elided Driver = /usr/lib/odbc/libtdsodbc.so Server=fqdn.example.com Port=4100 TDS Version = 5.0 [a] Description = a server, name elided Driver = /usr/lib/odbc/libtdsodbc.so Server=fqdn2.example.com Port=4100 TDS Version = 5.0 Test with this command: isql -v d user pass where d is the 'd' from the odbc file, and user and pass are the actual ones. Oh, and you have to add /var/lib/gems/*/bin to your path. * is 1.8 in my case. And remove the symlinks from my vendor/ directory, and maybe regenerate a few files with "rails .", as I was doing this to an existing project. Update: Formatting! Update: Added the Gem::Exception error as google-bait. Last updated: Jul 06 2009 16:44 |
|