Mysql – Ruby on rails connection problem


I have a Ruby on Rails project that I was developing on a hosted server but have decided to work on my local windows machine with.

To get started I thought I'd make sure that I could just take my models from the old project and put them in a new project then query them in the console. This fails.

Edit to reflect more accurate problem:
The connection that rails builds to query my models can run only one query then gives the "Not connected" exception for all subsequent queries. Anybody know what's going on? I've checked my configuration, a lot. If there's some setting on mysql server that I don't know about I'd be willing to look at that.

Stack Trace:

ActiveRecord::StatementInvalid: Mysql::Error: query: not connected: SHOW FIELDS FROM `prices`
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:466:in `columns'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1271:in `columns'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1279:in `columns_hash'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1578:in `find_one'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1569:in `find_from_ids'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:616:in `find'
        from (irb):2

I've verified that my MySQL database is accepting connections and has the data and structure I expect. I've double checked my connections, etc. Can anyone shed some light?

Best Solution

I found a solution to this problem in an aptana forum.

There it says that the MySQL 5.1 client library doesn't play well with Rails 2.2 The solution they offer is simple: download an older MySQL client library (libmySQL.dll) and copy it to your Ruby\bin folder.

This worked for me (Windows XP, Ruby 1.8.6, Rails 2.3.3, mysql 5.1.33)

Related Question