Rails 菜鸟求教:报错 “ActiveRecord::ConnectionNotEstablished”

ghyghoo8 · January 25, 2012 · Last by zhangner replied at November 14, 2012 · 8468 hits
Started GET "/say/hello" for 127.0.0.1 at 2012-01-25 11:33:35 +0800

ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):


Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered C:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (6.0ms)

网上查了很多答案,都是说数据库未连接什么的,但是,我检查了配置:

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: hw2_development
  pool: 5
  username: root
  password:123
  host: localhost

貌似没什么错误啊,连接正常 sqlite3 也装了。。。。 话说,首页http://127.0.0.1:3000请求个图片都请求不了:

Started GET "/assets/rails.png" for 127.0.0.1 at 2012-01-25 11:05:12 +0800
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
......

求高手帮忙解答呀…… 诚心学习 ing

没创建数据库吧,rake db:create

贴个浏览器中的页面提示上来吧! 另外你不会还用 mysql 吧,现在 adapter 好像都用 mysql2 了

*貌似没什么错误啊,连接正常 sqlite3 也装了。。。。 * 你到底用的 sqlite3 还是 mysql 啊老兄。。。

#2 楼 @clc3123 页面上的错误是这样的:

ActiveRecord::ConnectionNotEstablished

ActiveRecord::ConnectionNotEstablished

Rails.root: D:/ruby/hw2
Application Trace | Framework Trace | Full Trace

activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
activerecord (3.1.0) lib/active_record/query_cache.rb:65:in `rescue in call'
activerecord (3.1.0) lib/active_record/query_cache.rb:59:in `call'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0) lib/rails/engine.rb:455:in `call'
railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
C:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

#1 楼 @ywencn 我用的 RubyMini ,应该怎么操作。写个 rails 的 hello world 这么难得……

#4 楼 @ghyghoo8

  1. 你的 mysql 启动成功了吗?
  2. 写个 hello world 干嘛用 mysql 呢。mysql 还要另外安装配置。用 sqlite3 就可以啦!

#5 楼 @ichord 啊~绝对成功启动了,我只对 mysql 熟悉啊。只有 public 目录下面的文件能正常访问,其他的都会 ActiveRecord::ConnectionNotEstablished,然后就是上面的错误 trace。。。T.T

#6 楼 @ghyghoo8 噢...你说装了 sqlite3 的 adapter. 那你装了 mysql 的了吗?

#6 楼 @ghyghoo8 这样吧,你创建一个新项目,然后生成一个 scaffold,跑起来看看有没有问题,然后对比一下吧,包括 database.yml, Gemfile, Gemfile.lock 等文件:

rails new my_awesome_project -d mysql

写 hello world 用的是 mysql 的话那说明你入门看错书了

适配器换 mysql2 看看

要寫 mysql2

写个 hello World 怎么会把数据库给拉上,你的这个数据库文件是自动生成的吗?还是你自己写的? 你不如再写详细点。。。这个确实还看不出哪里的问题

我在看 rails tutorial 的时候,也遇到了这个问题

奇怪的时我 development 配置的是 sqlite3, 最后是在 Gemfile 里指定了 mysql 才解决了这个问题

但是我就没有需要 mysql 数据库啊?

1.Gemfile 中使用的 mysql 的 gem 不会是 mysql2 吧? 2.ruby/bin/下面的libmysql.dll版本是ok的?gem install mysql 的时候会有提示的

You need to Sign in before reply, if you don't have an account, please Sign up first.