Geeks With Blogs
Enginerding Alex Moore

On a recent project I needed to test my application with lots of data so I remembered my good friend the Faker Gem from the Ruby world. 
I didn’t know how to connect ActiveRecord to SQL Server, so I searched the webs and found this article by Ray Houston at Los Techies
Unfortunately since the article was 13 months old, the Ruby libraries have evolved to not work that way anymore :)  So after some head scratching I got it to work again.

How to connect ActiveRecord to SQL Server

  1. If you don’t have Ruby installed, grab the one-click installer from http://rubyforge.org/frs/?group_id=167&release_id=28426 and make sure you check the box to install rubygems.
  2. Open up your PowerShell or console, and run: 
    gem update ––system
    gem install activerecord activerecord-sqlserver-adapter
    *This should install all prerequisites gems as well.
  3. Grab my example from github:
    http://github.com/alexmoore/activerecord-with-sqlserver-example/tree/master
  4. Run the CreatePersonTable.sql script to add the example table to your database.
  5. Open Config.rb and put your database connection info in.
  6. Run: ruby PersonFactory.rb  and you should be golden!

In my next post I will show how to use the Faker gem and some statistics tricks to quickly mock up a plethora of test data.

-- Alex

Posted on Monday, August 17, 2009 12:11 AM Ruby , Sql Server | Back to top


Comments on this post: Using ActiveRecord with SQL Server 2000/2005/2008

# re: Using ActiveRecord with SQL Server 2000/2005/2008
Requesting Gravatar...
Thanks very much, worked great. Still don't get how I can get ADO to work in irb but not for db:migrate. But the ODBC method you used seems to work just fine.
Left by Sketchy on Oct 23, 2009 2:29 PM

# re: Using ActiveRecord with SQL Server 2000/2005/2008
Requesting Gravatar...
Good post. Thanks a lot.
Left by Ryan on Jul 02, 2010 9:29 AM

Your comment:
 (will show your gravatar)


Copyright © Alex Moore | Powered by: GeeksWithBlogs.net