Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to an MSSQL database from a Ruby on Rails application running on Ubuntu

I have a situation where I'm trying to build a web app which takes a total count of records in a table and outputs it to the screen. Sounds simple right...?

The main problem I'm having is that the DB I want to look at is MSSQL. I haven't set up this kind of DB connection from Rails before so I was hoping someone could point me in the right direction.

My RoR application will live on a Ubuntu server (and is being developed on a OSX Leopard system).

EDIT:

  • I should clarify that the MSSQL DB is running on SQL server 2005 and is on a windows server environment.

  • I tried checking out the wiki.rubyonrails.org guide but the site seems to be down (sad)

Thanks!

like image 491
Ganesh Shankar Avatar asked Mar 03 '11 03:03

Ganesh Shankar


2 Answers

This Stackoverflow question might help: Rails & MSSQL 2008 - Will We Hit Barriers?

Basically you will need to install a MSSQL database adapter (rather than MySQL or Postgres that most tutorials step you through), and configure your database.yml appropriately:

http://rorblog.techcfl.com/2008/04/14/ruby-on-rails-connection-to-sql-server/

http://the-banana-peel.saltybanana.com/2008/06/connecto-to-microsoft-sql-server-from.html

http://wiki.rubyonrails.org/database-support/ms-sql (Although the rails wiki looks down at time of writing)

P.S. I am assuming the MSSQL server will be running on a separate Microsoft server someplace.

like image 130
Clinton Avatar answered Sep 22 '22 10:09

Clinton


Take a look at an example I've made on how to use the mentioned actionrecord-sqlserver adaptor here

You can use mappings with rails models and use the ActiveModel helpers.

like image 40
Paulo Fidalgo Avatar answered Sep 22 '22 10:09

Paulo Fidalgo