Thursday, November 10, 2011

Rails, SQL Server 2008 & Windows - Tips and Tricks !!

In this post, I will be discussing in short about the configuration one need's to do for Rails, SQL Server 2008 and Windows XP system.


My configuration in my current system is:


1. Ruby: ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32]
2. Rails 2.3.8 
3. OS: Windows XP.
4. SQL Server 2008


Note, that I have downloaded Ruby from rubyinstaller site, the link is mentioned below in this post.
First of all, we need two gems to be installed in our system to work with SQL Server 2008


1. activerecord-sqlserver-adapter, command for installation: gem install activerecord-sqlserver-adapter -v=2.3.6


2. ruby-odbc, command for installation: gem install ruby-odbc


Please note, without these two gems thing will not work properly.


activerecord-sqlserver-adapter has other higher versions, which i presume works with rails 3.0 + versions. For my purpose, I have used the version, 2.3.6
Before installing, ruby-odbc gem, you will need to install the ruby development kit from the ruby installer site. The links for rubyinstaller site are:


1. http://rubyinstaller.org/
2. http://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe
3. https://github.com/oneclick/rubyinstaller/wiki/Development-Kit (installation instructions can be found out here)


Without installing the devkit, the ruby-odbc gem will not be able to install.


Now, in the next step, we will have to create  dsn link for odbc connection.You can get a idea about to create it by going through this link: http://www.ehow.com/how_4642566_setup-odbc-database-connection.html


Once, the dsn link is done and lets assume that you have named it as dsn_link, you have to enter the information in your database.yml file. Here is a snapshot of my database.yml


development:
  adapter: sqlserver
  mode: odbc
  dsn: dsn_link
  username: my_username
  password: my_password



This is it !!. Restart your development server and now your application will be pointing to the SQL server configuration :)