Connecting to MSSQL works in IRB, but not rails


I am attempting to get code working that connects to a MS SQL server
from a Linux web server. My testing in irb works, but when I try it in
rails I have no such luck. Sorry about the long post.

I have install and tested FreeTDS (works), and unixODBC (works). I
have a working ODBC connector called CTEL.

I have also installed RubyDBI and RubyODBC. I tested those by starting
irb1.8 and executing the following code:

require "dbi"
dbh = DBI.connect('dbi:ODBC:CTEL', 'usrename', 'password')
sth = dbh.execute("SELECT Org_ID FROM Org")
while row = sth.fetch do
  print row

(Where username and password are the correct values.) It works
perfectly and prints out all of the Org_IDs. So, it looks like I have
all of the prereqs workings and life is good.

However, when I start working in rails things don't go as smoothly. My
database.yml looks like:

  adapter: sqlserver
  mode: odbc
  dsn: CTEL
  username: ************
  password: *************

My model is legacy_customer.rb:

class LegacyCustomer < ActiveRecord::Base

  establish_connection :ctel
  set_table_name :Org
  set_primary_key :Org_ID


Next I open up script/console and type "test =" and
get the following:

DBI::DatabaseError: INTERN (0) [RubyODBC]No data found
        from /usr/local/lib/site_ruby/1.8/DBD/ODBC/ODBC.rb:186:in `[]='
        from /usr/local/lib/site_ruby/1.8/dbi/dbi.rb:733:in `[]='
        from (irb):1:in `new'
        from (irb):1

Any ideas on what I could do from here?

Thanks for the help,

Any body? I still haven't had much luck resolving this issue, so I
would definitely appreciate any suggestions.


If you have text columns that have empty strings this error will occur.
It's a bug in RubyODBC. Make sure that the text columns are either NULL
or have some data in them.

gnubbs wrote: