Connecting Rails’s ActiveRecord to Azure SQL Database

Spec
1. Local development on Ubuntu
2. Rails 4
3. Azure sql server database

How To
1. Install freetds compiled with openssl

sudo wget ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz
sudo tar -xvf freetds-stable.tgz
cd freetds-stable
sudo apt-get install gcc libssl-dev
./configure --prefix=/usr/local --with-libiconv-prefix=DIR --with-openssl=DIR --with-tdsver=7.3
sudo make
sudo make install

After this you should be able to run:

tsql -C

And get:

Compile-time settings (established with the “configure” script)
Version: freetds v0.91
freetds.conf directory: /usr/local/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0
iODBC: no
unixodbc: no
SSPI “trusted” logins: no
Kerberos: no

2. Add these to Gemfile

gem 'tiny_tds'

gem 'activerecord-sqlserver-adapter', git: 'https://github.com/arthrex/activerecord-sqlserver-adapter.git'

3. Run bundle to install gems

bundle install

4. Edit database.yml

development:  

  adapter: sqlserver    
  mode: dblib    
  host: your_host.database.windows.net port: 1433 database: your_db_name username: your_username password: your_password timeout: 5000 azure: true

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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