Gnana Prasad Ruby

April 28, 2008

Connecting to a Microsoft SQL Server from a Rails Application

Filed under: Uncategorized — gnanaruby @ 10:33 am

This is just a quick note for those of you that have a Ruby on Rails application that you are connecting up to Microsoft SQL server for your database.

Step 1) Download the latest ruby-dbi package

Rails has a database independent interface (DBI) that can be downloaded from RubyForge

Step 2) After downloading extract the dbi-<latest version>.tar.gz (Example : dbi-0.1.1.tar.gz )

Step 3) Copy the file ADO.rb file from

                      bdi-0.1.0/lib/dbd/ADO.rb
                              To 
 
                        c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb
 
NOTE: The ADO directory does not exist on a standard install; you will need to create it.
 

Step 4) Copy the sqlserver_adapter.rb file into the ruby installed gems path as specified below:

    C:\ruby\lib\ruby\gems\1.8\gems\activerecord-2.0.2\lib\active_record\connection_adapters\

Step 5) Then simply set up your railsapp/config/database.yml

Here’s an example for reference:

development:
  adapter: sqlserver
  database: database_name
  host: server_name
  username: user_name
  password: your_pw_here

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.