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 169011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:33:17+00:00 2026-05-11T12:33:17+00:00

Have you ever had to connect to SQL Server with ActiveRecord? Is this possible?

  • 0

Have you ever had to connect to SQL Server with ActiveRecord? Is this possible? Can anyone provide some starting points?

  • 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. 2026-05-11T12:33:18+00:00Added an answer on May 11, 2026 at 12:33 pm

    This what I used:

    From here: http://github.com/rails-sqlserver/2000-2005-adapter/tree/master

    Installation

    First, you will need Ruby DBI and Ruby ODBC. To my knowledge the ADO DBD for DBI is no longer supported. The installation below is not a comprehensive walk thru on how to get all the required moving parts like FreeTDS installed and/or configured. It will also assume gem installations of both the dependent libraries and the adapter itself.

    It should be noted that this version of the adapter was developed using both the ancient 0.0.23 version of DBI up to the current stable release of 0.4.0. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.0 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.0. The good news is that if you were using a very old DBI with ADO, technically this adapter will still work for you, but be warned your path is getting old and may not be supported for long.

    $ gem install dbi --version 0.4.0 $ gem install dbd-odbc --version 0.2.4 $ gem install rails-sqlserver-2000-2005-adapter -s http://gems.github.com 

    From here: http://lambie.org/2008/02/28/connecting-to-an-mssql-database-from-ruby-on-ubuntu/

    Firstly, update your ~/.profile to include the following:

    export ODBCINI=/etc/odbc.ini export ODBCSYSINI=/etc export FREETDSCONF=/etc/freetds/freetds.conf 

    Then reload your .profile, by logging out and in again.

    Secondly, on Ubuntu 7.10 Server I needed to install some packages.

    mlambie@ubuntu:~$ sudo aptitude install unixodbc unixodbc-dev freetds-dev sqsh tdsodbc  

    With FreeTDS installed I could configure it like this:

    mlambie@ubuntu:/etc/freetds$ cat freetds.conf [ACUMENSERVER]   host = 192.168.0.10   port = 1433   tds version = 7.0 

    The important thing here is ACUMENSERVER, which is the DSN that I’ll use when connecting to the database. The host, and port are self-explanatory, and it’s worth noting that I had to use 7.0 specifically as the tds version.

    Testing FreeTDS is not too hard:

    mlambie@ubuntu:~$ sqsh -S ACUMENSERVER -U username -P password sqsh: Symbol `_XmStrings' has different size in shared object, consider re-linking sqsh-2.1 Copyright (C) 1995-2001 Scott C. Gray This is free software with ABSOLUTELY NO WARRANTY For more information type '\warranty' 1> use acumen 2> go 1> select top 1 firstname, lastname from tblClients 2> go  [record returned]  (1 row affected) 1> quit 

    Next up it’s necessary to configure ODBC:

    mlambie@ubuntu:/etc$ cat odbcinst.ini [FreeTDS] Description     = TDS driver (Sybase/MS SQL) Driver          = /usr/lib/odbc/libtdsodbc.so Setup           = /usr/lib/odbc/libtdsS.so CPTimeout       = CPReuse         = FileUsage       = 1  mlambie@ubuntu:/etc$ cat odbc.ini [ACUMENSERVER] Driver          = FreeTDS Description     = ODBC connection via FreeTDS Trace           = No Servername      = ACUMENSERVER Database        = ACUMEN 

    I then tested the connection with isql:

    mlambie@ubuntu:~$ isql -v ACUMENSERVER username password +---------------------------------------+ | Connected!                            | |                                       | | sql-statement                         | | help [tablename]                      | | quit                                  | |                                       | +---------------------------------------+ SQL> use ACUMEN [][unixODBC][FreeTDS][SQL Server]Changed database context to 'Acumen'. [ISQL]INFO: SQLExecute returned SQL_SUCCESS_WITH_INFO SQLRowCount returns -1 SQL> select top 1 firstname from tblClients;  [record returned]  SQLRowCount returns 1 1 rows fetched SQL> quit 

    OK, so we’ve got ODBC using FreeTDS to connect to a remote MSSQL server. All that’s left is to add Ruby into the mix.

    mlambie@ubuntu:~$ sudo aptitude install libdbd-odbc-ruby 

    The last thing to test is that Ruby can use DBI and ODBC to hit the actual database, and that’s easy to test:

    mlambie@ubuntu:~$ irb irb(main):001:0> require 'dbi'  => true irb(main):002:0> dbh = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password') => #<DBI::DatabaseHandle:0xb7ac57f8 @handle=#<DBI::DBD::ODBC::Database:0xb7ac5744 @handle=#<odbc::database:0xb7ac576c>, @attr={}>, @trace_output=#</odbc::database:0xb7ac576c><io:0xb7cbff54>, @trace_mode=2> irb(main):003:0> quit 

    And a more complete test (only with SQL SELECT, mind you):

    #!/usr/bin/env ruby  require 'dbi' db = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password') select = db.prepare('SELECT TOP 10 firstname FROM tblClients') select.execute while rec = select.fetch do   puts rec.to_s end db.disconnect </io:0xb7cbff54> 

    From here (to fix the odbc lib being in the wrong place): http://ubuntuforums.org/showthread.php?t=433435&page=2

    libtdsodbc.so with freeTDS (freetds-dev, tdsodbc), you can either edit the path in the odbcinst.ini file for the [FreeTDS] driver section OR cp the /usr/lib/odbc/libtdsodbc.so into /usr/lib/libtdsodbc.so. 

    either way works when accessing mssql from the prompt

    isql -v $dsn $user $passwd 

    i found this to be useful

    http://www.unixodbc.org/doc/FreeTDS.html#Configuration

    And then in the database.yml file:

    development:   adapter: sqlserver   mode: odbc   dsn: dsn_name   username: my_username   password: my_password 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer BEWARE! This answer contains a severe SQL injection vulnerability. Do… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer Will the SUMIF function work for you? SUMIF([range],[criteria],[sum_range]) I think… May 11, 2026 at 6:02 pm
  • Editorial Team
    Editorial Team added an answer C# Express is an IDE (Integrated Development Environment), not just… May 11, 2026 at 6:02 pm

Related Questions

Have you ever had to use bit shifting in real programming projects? Most (if
At a previous employer, we were writing binary messages that had to go over
Have you ever had alternating background colors in a Jasper report and then exported
Setup Have you ever had the experience of going into a piece of code

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.