Home > Ruby on Rails > Connecting Ruby on Rails to Microsoft SQL Server

Connecting Ruby on Rails to Microsoft SQL Server

7 April, 2006

NOTE: These instructions are now seriously out of date. You may want to check out my always up to date ebook instead. The secret of connecting Rails to Microsoft SQL Server

It appears rails does not connect to MS SQL Server right out of the box. You need to do the following to get the connection to work:

Get the latest source distribution of Ruby-DBI and copy the file:




NOTE: The ADO directory does not exist on a standard install, you will need to create it.

Then simply set up your railsapp/config/database.yml

Here’s an example for reference:

  adapter: sqlserver
  database: database_name
  host: server_name
  username: user_name
  password: your_pw_here
Categories: Ruby on Rails
  1. 1 November, 2006 at 10:36 am

    Thanx for the advice. After installing the ADO stuff, I was able to connect to SQL 2005 without any problems. Cheers…

  2. Tom
    14 November, 2006 at 8:51 pm

    Has anyone connected from a Linux Rails application to a Microsoft SQL server?

  3. Blake Miller
    13 December, 2006 at 12:23 am


    Nope, no one has ever connected a Linux Rails app to a Microsoft SQL server, because the database adapter depends on Win32OLE, which is not available in any form under Linux.

    I am upset about this, too, as it might mean deploying my Rails app on Windows. A huge lump wells up in my throat at the mere idea of it . . . 8′(

  4. Hugo Villero
    9 July, 2007 at 6:51 pm

    Hi, what about to use diferent port in the database, Imeant not “1433” with the DBI, Do you know guys how to put that port in the .establish_connection ?

    Thank you for your help.

  5. Tom
    15 October, 2007 at 2:24 am

    I get the following error message on my Mac when I follow these instructions:

    “DBI::InterfaceError: Could not load driver (no such file to load — win32ole)”

  6. IronRuby
    19 December, 2007 at 8:02 am


    Can any one upload the Ruby-DBI zip file please to make it run with SQL 2005 Express.

    I am having problems to extract 0.1.1 tar.gz.

    I do not know how to extract such files. Pl. upload i a zip file if any one have it.


  7. vikram n
    6 February, 2008 at 5:46 pm

    this is what my config looks like
    adapter: sqlserver
    database: mydb
    username: railsuser
    password: 123

    I get the following error message
    >> ActiveRecord::Base.connection
    DBI::DatabaseError: Open
    OLE error code:80004005 in Microsoft OLE DB Provider for SQL Server
    [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access
    HRESULT error code:0x80020009
    Exception occurred.
    from C:/workspace/02_05_2008/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb:
    57:in `connect’

    any idea why ?

  1. 1 November, 2006 at 10:40 am
Comments are closed.
%d bloggers like this: