MS SQL Server

What is left is to learn is how to use database engine that is probably of the most interest for developers who work on Windows – Microsoft's SQL Server. If you do not have MS SQL Server installed go ahead and download MS SQL Server Express installer from Microsoft's site. I will use version 2014 in this book. Let's first create database that we will use in our Rails application:

osql -b -S localhost -U <your_sqlserver_admin_username> -P <password_here> -Q "CREATE DATABASE RwinBookDevel COLLATE SQL_Latin1_General_CP1_CS_AS"

Newest rails adapter for MS SQL Server uses tiny_tds library to connect to MS SQL server and its usage is almost straigtforward. First thing we have to do is to add following two lines to Gemfile:

gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'

and run bundle install. With all prerequisites met we can now configure our Ruby on Rails application to use SQL Server. Connection options are displayed below:

development:
  adapter: sqlserver
  mode: dblib
  host: localhost
  port: 1433
  username: <your_db_user_name>
  password: <your_db_password>
  database: RwinBookDevel

This is all you need to use MS SQL server for Rails application. Pretty easy, isn't it.