views:

90

answers:

2

I am trying to connect a Rails app on a Windows machine to SQL Server using activerecord-sqlserver-adapter. I have set up a DSN that works great.

When I try to run a migration (or any database operation), I am informed:

"no such file to load -- odbc"

My database.yaml file has this:

development:
  adapter: sqlserver
  mode: odbc
  dsn: rails_import

I used the one-click ruby installer which I thought would install any gems needed for odbc. Maybe I'm wrong.

How do I get past this error? I have been Googling for an hour with no luck. Thanks in advance.

+1  A: 

Make sure you have the dbi and dbd-odbc gems installed:

gem install dbi
gem install dbd-odbc

Also, you can setup the DSN as a connection paramater in database.yml:

dsn: Driver={SQL Native Client};Server=.\SQLEXPRESS;Database=rails_database_name;

sespindola
Still no luck - I get the same error. Good tip on the dsn value though.
retailevolved
A: 

Fixed it! Here's how (in case anybody else has a similar issue).

Ruby was basically telling me that the 'odbc' gem was not available. I had incorrectly assumed that the RubyInstaller would install this for me (based on other reading). So, I needed to install ruby-odbc.

For me, this wasn't terribly straight forward since I don't have an environment that allows me to compile C. Fortunately, RubyInstaller has a dev kit. Download that, and follow the install instructions to a t.

After installing that, run: gem install ruby-odbc. That fixed it up for me.

retailevolved