Connecting to a Microsoft SQL Server from a Rails Application
Posted by Tom Rossi on October 13, 2006Comments (3)
Ruby on Rails
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. Hopefully this can save you some time!
As a note, some of you may be asking WHY? Why would you want to connect to Microsoft SQL when MySQL does the job just fine? Well, at the Molehill we are working on migrating one of our old Microsoft .NET applications to the Ruby on Rails framework and mapping to the legacy database during the migration is a great way to expose some functionality in the meantime.
Download the latest DBI
Rails has a database independent interface that can be downloaded from RubyForge. It can be a little confusing and if you don't have an application to uncompress a tar.gz file, you can download it here from our site. The file you are looking for is ADO.rb. This file should be placed in the following directory:
/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/
Depending on the version of Ruby you have installed, the 1.8 may be different. Also, the ADO folder may not already exist so you may need to create it.
Create your database.yml
Now you will modify your adapter in your database.yml file to be sqlserver. Here is an example:
development: adapter: sqlserver database: dbmydatabase host: sqlserver.domain.com username: user password: secret
Thats it! Now ActiveRecord will be able to access your tables on your MS SQL server!
Give us a piece of your mind.
3 comments thus far - add yours