Ensure you done the initial setup for SQL Server and ActiveRecord (ADO.rb).
require 'rubygems' require_gem 'activerecord' ActiveRecord::Base.establish_connection( :adapter => "sqlserver", :dsn => "instance_name_goes_here", :host => "machine_name\\instance_name", :database => "db_name", :username => "my_username", :password => "my_password" ) class MsSqlTable < ActiveRecord::Base def method_missing(method, *args) respond_to?(method) ? super : send(method.to_s.camelize, *args) end end class Item < MsSqlTable set_primary_key "sku" set_table_name "item" end
I'll walk through it real quick:
1. The :dsn needs to be your SQL Server instance name
2. The :host needs to a path like "myserver\myinstance", even though you've already specified the instance name in the :dsn parameter
3. The rest of the settings should be obvious. If your password is blank, don't specify :password at all.
4. Our legacy column names are things like OldDescription. So I created an intermediate base class that would provide ruby-like aliases. Now I can use item.old_description instead if I want to.
5. Finally, I declare one class for each table I want to access. I have to set the primary key and table name manually, since our tables don't correspond to any Rails conventions.
I saved this script as legacy.rb, and then fired up irb from that directory:
irb> load 'legacy.rb' => true irb> Item.find("191191").old_description => "Table In A Bag" irb>