Eric Guo's

Hoping writing JS, Ruby & Rails and Go article, but fallback to DevOps note

Rails With SQL Server Gem Install


Ubuntu 12.04 LTS already have the freetds package, so just running below command will install SQL Server support for Rails.

install tiny_tds
apt-get install freetds-dev tdsodbc
gem install tiny_tds
gem install activerecord-sqlserver-adapter
add below line to odbcinst.ini
Description = ODBC for Microsoft SQL
#choose one of line based on your version
Driver = /usr/lib/i386-linux-gnu/odbc/
Driver = /usr/lib/x86_64-linux-gnu/odbc/
UsageCount = 1
Threading = 2

About the driver location, you may need to find the libtdsodbc first at via find /usr/lib -name

add below line to odbc.ini
Description = MS SQL connection to 'SDSS' database
Driver = FreeTDS
Database = TECN
ServerName = CVPALPIP01
Trace = No
add below line to freetds.conf
host =
port = 1433
tds version = 7.0 # or 8.0
add below line to database.yml
adapter: sqlserver
dataserver: '\SDSS'
database: TECN
username: only_read
password: only_read
and using it in model
# app/models/tecn.rb
class Tecn < ActiveRecord::Base
# No corresponding table in the DB.
self.abstract_class = true
def readonly?