Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:25:02+00:00 2026-05-17T19:25:02+00:00

I need to let my Rails app connect to a MS SQL Server database

  • 0

I need to let my Rails app connect to a MS SQL Server database and do a simple query to do a lookup. The main DB for the app is MySQL. It just needs to do this SQL Server thing on the side.

What’s the best way to do that?

I could write an entirely separate app in Java that connects to the DB and dumps some XML data to the filesystem for my Ruby app to pick up.

Or I could mess around with Ruby ODBC connectivity. I did a search on Gemcutter and found these…

  • dbd-odbc (0.2.5) 11141 downloads
  • ruby-odbc (0.99992) 6390 downloads
  • activerecord-odbc-adapter (2.0) 2333 downloads
  • odbc-rails (1.5) 2167 downloads

It would mean connecting to two different DBs from one Rails app, though. I’m not even sure how to do that.

Does anyone have experience working with SQL Server in Ruby? Any thoughts on which approach is most practical?


UPDATE — got it working

Thanks for the help. Based on the answers and some research I worked it out. I’m going to paste my notes below. Sorry for the casual tone. I just copied them over.

Steps taken to connect to SQL Server with Ruby on OS X

Download, configure, build FreeTDS library

The docs are pretty detailed and clearly written, mostly. There are a few rough spots in crucial places that cost me a few hours of troubleshooting.

By default it installs into /usr/local/freetds/lib.

That gives you a bunch of utilities and stuff. They can help with testing and troubleshooting.

For example, from the docs: “The tsql utility is provided as part of FreeTDS expressly for troubleshooting.”

Added this to /etc/profile:

# 2010-10-19
# To support the FreeTDS library for connecting Ruby to SQL Server.

PATH=$PATH:/usr/local/freetds/bin

# Have FreeTDS to log some output.
#export TDSDUMP=/tmp/freetds.log
#export TDSDUMPCONFIG=/tmp/freetdb_config.log

export PATH

FreeTDS config file

Need to create a config file for FreeTDS. The docs list several places where that can be stored. The only one that worked for me was ~/.freetds.conf…

[DATA_SERVER_NAME]
    host = hostname
    port = 1433
    tds version = 8.0

That’s the whole config. For the [DATA_SERVER_NAME] you can’t use the hostname or it won’t work. Use some intuitive logical name. You’ll use that name when you hook up to it inside Ruby code with the tiny_tds gem.

Don’t need to set up ODBC

Despite what it says in the FreeTDS docs, there’s no need to create a odbc.ini or a odbcinst.ini file. It works without it.

Installed tiny_tds gem

The tiny_tds gem connects Ruby to FreeTDS to an SQL Server database. In the tiny_tds docs it says…

‘…please make sure to compile FreeTDS with libiconv support for encodings to work at their best. Run “tsql -C” in your console and check for “iconv library: yes”.’

I was able to do that and it worked.

It’s supposed to work like this:

require 'tiny_tds'
client = TinyTds::Client.new(:username => '...username...', :password => '...password...', :dataserver => 'DATA_SERVER_NAME')
sql = '... whatever ...'
result = client.execute(sql)
client.close

ActiveRecord

Supposedly you can use ActiveRecord with SQL Server after you get all that set up by installing the activerecord-sqlserver-adapter gem. I didn’t need that so I didn’t install it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:25:03+00:00Added an answer on May 17, 2026 at 7:25 pm

    There is currently a lot of development going on with the necessary gems for connecting to MS SQL.

    Short summary:

    • you no longer need dbi or dbd. ( The guide posted by c0r0ner is to old )
    • all you need is freetds, ruby-odbc and activerecord-sqlserver-adapter
      ( follow the guide from Xavier Shay posted by wuputah )
    • look out for tiny_tds coming soon as a replacement for ruby-odbc
      It makes the configuration even simpler and faster access to the database
      ( http://github.com/rails-sqlserver/tiny_tds )
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to let service sleep for 0.5 sec just as using Thread.sleep(); is
I find a common issue in my RESTful Rails apps controllers that respond to
I'm currently looking at hosting solutions for my Ruby on Rails SaaS web application,
I am working on a Rails 3 project that relies heavily on screen scraping
OK, so I've been toying with different ways of organizing my Rails 3 apps
I cannot get this crazy dependency to work and please don't tell me to
We have an in house developed web-based admin console that uses a combination of
Sorry i really didn't know how to phrase the question any better but here
I have read all the blog posts on digital signing and checked out GoDaddy
I remember there were some kind of fancy, super-special CALayer types or classes for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.