How To: Rails with SQL Server 2008

November 1, 2009

Most common database used with Rails is mySQL but if you ever need to use SQL Server, here is a quick how to.

I am using  Windows Vista, SQL Server 2008, Rails 2.2.

1)  Install  activerecord-sqlserver-adapter gem

 > gem install activerecord-sqlserver-adapter


2) Create a new Login for this new database (say testuser) using SQL Server Management Studio


3) Create a new database in SQL Server 2008 for your project (say testproject) and choose testuser as Owner


4) Create a new ODBC DNS

Control Panel -> Administrative Tools -> Data Sources (ODBC)


Add a new ‘User DSN’,  choose SQL Server,  give a name for DSN (say testprojectconn) then configure SQL Server authentication.

5) Now create your rails application as usual.  Configure db connection using database.yml as follows

  adapter: sqlserver
  mode: odbc
  dsn: testprojectconn
  host: localhost
  username: testuser
  password: testpass
  encoding: utf8

Thats it!


2 Responses to “How To: Rails with SQL Server 2008”

  1. […] dati (ad esempio testuser) utilizzando SQL Server Management Studio 3) Creare un nuovo […] From: N Rao Lakkakula’s Blog. Continue reading. Categorie:Senza categoria Tag: Commenti (0) Trackbacks (0) Lascia un […]

  2. Anonymous Says:

    thank you~

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: