开发者

Rails on windows connect to Microsoft SQL Server - "no such file to load -- odbc"

开发者 https://www.devze.com 2023-01-08 17:04 出处:网络
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.

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.


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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消