"Unable to load driver 'ODBC'" on windows w/ruby 1.9

1,434 views
Skip to first unread message

Roy

unread,
Jan 8, 2010, 7:16:54 PM1/8/10
to Rails SQLServer Adapter
Hey All,

I'm trying to use the sql server adapter on a windows XP machine from
a plain ruby script and am getting the subject error. Here's my
script:

# ===================
require 'dbi'
require 'activerecord'
require 'activerecord-sqlserver-adapter'

db_config = { :adapter => 'sqlserver',
:mode => 'ODBC',
:server => 'ctrhs-sql2k\sql2k',
:database => 'eHealth',
:dsn => 'Driver={SQL Server Native Client 10.0};Server=ctrhs-
sql2k\sql2k;Database=eHealth;Trusted_Connection=Yes'
}

::ActiveRecord::Base.establish_connection(db_config)
c = ::ActiveRecord::Base.connection
puts(c.inspect)
puts(c.methods.sort.join("\n"))
# ===================

Probably that :dsn isn't completely kosher, but I'm not even getting
that far. On the require 'dbd-odbc' line I get

parse_docs.rb:5:in `require': no such file to load -- dbd-odbc
(LoadError) from
parse_docs.rb:5:in `<main>'

If I comment-out that require I get:

c:/ruby19/lib/ruby/gems/1.9.1/gems/dbi-0.4.3/lib/dbi.rb:300:in
`block in
load_driver': Unable to load driver 'ODBC' (underlying error:
uninitialized
constant DBI::DBD::ODBC) (DBI::InterfaceError)

on the line:

c = ::ActiveRecord::Base.connection

My googling on the first error mostly turns up references to ruby-odbc
(http://www.ch-werner.de/rubyodbc/) but my attempts to install that
have failed--it seems to be a unix thing?

I do indeed have dbd-odbc installed--gem list --local gives me (in
part):

activerecord (2.3.4, 2.3.3)
activerecord-sqlserver-adapter (2.2.22)
dbd-odbc (0.2.4)
dbi (0.4.3, 0.4.1)

What can I do to get this working?

Many thanks!

-Roy

Ken Collins

unread,
Jan 8, 2010, 7:26:22 PM1/8/10
to rails-sqlse...@googlegroups.com

The dbd-odbc companion of the DBI library is required, just install and require that gem too. Remember, the adapter requires dbi v0.4.1 and dbd-odbc v0.2.4.

- Ken

> --
> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> To post to this group, send email to rails-sqlse...@googlegroups.com.
> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.
>
>

Roy Pardee

unread,
Jan 8, 2010, 7:41:40 PM1/8/10
to rails-sqlse...@googlegroups.com
Thanks Ken!  I had dbi 0.4.3 as well as 0.4.1 installed, so I uninstalled 0.4.3, but am getting the same error on the line

  require 'dbd-odbc'

Namely:

  parse_docs_aborted_mssql_ar_attempt.rb:6:in `require': no such file to load -- dbd-odbc (LoadError)

I do have dbd-odbc v0.2.4 installed--here's a list of my gems:

actionmailer (2.3.4, 2.3.3)
actionpack (2.3.4, 2.3.3)

activerecord (2.3.4, 2.3.3)
activerecord-sqlserver-adapter (2.2.22)
activeresource (2.3.4, 2.3.3)
activesupport (2.3.4, 2.3.3)
BlueCloth (1.0.0)
dbd-mysql (0.4.3)
dbd-odbc (0.2.4)
dbi (0.4.1)

Thanks!

-Roy
--
Roy Pardee
http://facebook.com/rpardee

Ken Collins

unread,
Jan 8, 2010, 7:52:15 PM1/8/10
to rails-sqlse...@googlegroups.com

I'd have to see more of a longer code example and stack trace. I am also not familiar with supplying and the string straight out for just a raw connection. That said if you to, you could just kick up a blank rails app and test to make sure it works as well as put some debugging statements into the low level connect part of DBI to see what raw options to place.

 - Ken
Reply all
Reply to author
Forward
0 new messages