views:

4452

answers:

5

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?

+1  A: 

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

marcgg
Checked the gem several times, checked all of my gems in fact. I know the database configuration is correct because if I purposefully break it, I am no longer able to get information about my configuration (one or more of the server info-ish queries fail). For this same reason I know that it can communicate with Mysql, and that mysql is running (if I deactivate the service, I can no longer see information about my configuration from the welcome page).
marr75
+41  A: 

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)

bjelli
Sweet! Worked for me too :)
jsidnell
Thank you very much. It's disappointing that in the many places that the mysql and ruby projects link to each other, including step by step guides on how to get this stack working on windows, this item hasn't been mentioned.
marr75
Wow, glad I found this post! Works great now, thanks for the tip guys!
Mark Kadlec
A much appreciated timesaver!
yalestar
You the man. Worked great. Upvoted.
John Lockwood
THank you... THought I was in real trouble on migrating form a linux host to local windows demo server....
Eric Pugh
Upvoted again. I was getting different errors every time I tried to run a rake db:migrate. Segmentation faults and errors connecting left and right. It would have taken me hours to figure this out. Instead it took 5 minutes, with your link to a .dll file.
bergyman
+1 Works like a charm.
Jay
+1 you saved my day, thanks
markcial
Worked for me. Are you sure that is ok and safe to use and old mysql dll with mysql 5.1???
emzero
worked for me on rails 2.3.8, ruby 1.8.7
Straff
A: 

I think, the problem is hidden in paths mostly in compiling under Win32 env. Something incorrectly defined in the source of libmysql.dll for Win32. Honestly I don't have enough time to check but if you so kind, please, check it and tells a result to the community.

Ilya M.
A: 

Thank you for your posts the problem still persists.

Henry