Using ActiveRecord to connect to Sybase Adaptive Server Anywhere on Windows

December 21st, 2009

Just don’t ask why I know this. Please. It’s making me cry.

Install Ruby using the One Click Installer.
Install the ODBC module (by copying the SO files into the c:\Ruby\1.8\i386-mingw32 folder).
Install the ActiveRecord ODBC adapter (gem install activerecord-odbc-adapter).
Edit C:\Ruby\lib\ruby\gems\1.8\gems\activerecord-odbc-adapter-2.0\ lib\active_record\connection_adapters\odbc_adapter.rb – look for line 1588.
Change the line from elsif dbmsName =~ /SQLAnywhere/i to elsif dbmsName =~ /SQLAnywhere/i or dbmsName =~ /adaptiveserveranywhere/i

Write some test code – something like:


require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(:adapter => :odbc, :dsn => 'mydsn', :username => 'myusername', :password => 'mypassword')

class Whatever < ActiveRecord::Base

end

Whatever.all

Run this - hopefully you should get no errors.
Then sit down and have a long think about what the hell you are doing.

Comments are closed.