Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

Price.find(1)
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?

like image 996
marr75 Avatar asked Aug 27 '09 20:08

marr75


3 Answers

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)

like image 199
bjelli Avatar answered Nov 18 '22 15:11

bjelli


Check that you have the latest mysql gem (for rails > 2.1.2)

Verify your config/database.yml file (adapter, passwords). Check that it is set correctly for all the environments (dev, prod test)

Verify that your mysql is running

like image 35
marcgg Avatar answered Nov 18 '22 14:11

marcgg


download an older MySQL client library

like image 1
田咖啡 Avatar answered Nov 18 '22 15:11

田咖啡