28

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?

5
  • are you running in prod, dev or test? what happen if you change this? Commented Aug 27, 2009 at 20:23
  • Can connect, query fails >> require "mysql" => [] >> testconn = Mysql.real_connect("localhost", "lco_admin", "****", "lastcall_dev") => #<Mysql:0x348d728> >> testconn.get_server_info => "5.1.37-community" >> testconn.host_info => "localhost via TCP/IP" >> testconn.list_tables => ["bar_schedules", "bars", "bars_features", "drinks", "features", "prices", "recurrences", "special_schedules", "specials", "timespans"] >> testconn.query("select * from prices") Mysql::Error: query: not connected from (irb):7:in `query' from (irb):7 Commented Aug 27, 2009 at 20:30
  • I'm experiencing exactly the same problem as you @marr75. I'll definitely post to this if I work it out! Commented Aug 28, 2009 at 0:39
  • I'm not 'running' in anything. I'm using the console, which runs in dev, but I've changed the dev environment options to match prod and test and received the same errors, just to rule that kind of problem out. To restate, this application works fine on a hosted linux server, I'm just trying to get it going on my local windows machine. I can connect to the local mysql database and get server info, a tables list, etc. My queries just fail with the stack trace given. Commented Aug 28, 2009 at 15:49
  • a little more information, I can actually connect, and run a query if it's the very first thing I do, after that, the connection is no longer connected. Commented Aug 28, 2009 at 18:44

3 Answers 3

81

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)

Sign up to request clarification or add additional context in comments.

8 Comments

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.
Wow, glad I found this post! Works great now, thanks for the tip guys!
A much appreciated timesaver!
THank you... THought I was in real trouble on migrating form a linux host to local windows demo server....
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.
|
3

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

1 Comment

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).
1

download an older MySQL client library

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.