Forum: Ruby on Rails Database Error?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sean McGilvray (Guest)
on 2009-03-25 20:42
(Received via mailing list)
Hello everyone,
I am getting this database connection error when I run a rake task or
when I try to send with ar_mailer.  My app works fine that I know of
but I went to import users into the database and this is what I get.

rake db:load_csv_data --trace
(in /home/greatcar/gcp)
** Invoke db:load_csv_data (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_csv_data
rake aborted!
Access denied for user 'root'@'localhost' (using password: NO)
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/mysql_adapter.rb:548:in `real_connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/mysql_adapter.rb:548:in `connect'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/mysql_adapter.rb:198:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/mysql_adapter.rb:74:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/mysql_adapter.rb:74:in `mysql_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:223:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:223:in
`new_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:245:in
`checkout_new_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:188:in `checkout'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:184:in `loop'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:184:in `checkout'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:183:in `checkout'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:98:in `connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_pool.rb:326:in
`retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_specification.rb:121:in
`retrieve_connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
connection_adapters/abstract/connection_specification.rb:113:in
`connection'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
base.rb:1220:in `columns'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
base.rb:2839:in `attributes_from_column_definition_without_lock'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
locking/optimistic.rb:55:in `attributes_from_column_definition'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/
base.rb:2279:in `initialize'
/home/greatcar/gcp/lib/tasks/import.rake:9:in `new'
/home/greatcar/gcp/lib/tasks/import.rake:9
/usr/lib/ruby/gems/1.8/gems/fastercsv-1.4.0/lib/faster_csv.rb:1514:in
`each'
/usr/lib/ruby/gems/1.8/gems/fastercsv-1.4.0/lib/faster_csv.rb:1017:in
`foreach'
/usr/lib/ruby/gems/1.8/gems/fastercsv-1.4.0/lib/faster_csv.rb:1191:in
`open'
/usr/lib/ruby/gems/1.8/gems/fastercsv-1.4.0/lib/faster_csv.rb:1016:in
`foreach'
/home/greatcar/gcp/lib/tasks/import.rake:8
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in
`invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in
`invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in
`invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19

Thanks for the help,

Sean McGilvray
Frederick C. (Guest)
on 2009-03-25 20:56
(Received via mailing list)
On Mar 25, 6:41 pm, Sean McGilvray <removed_email_address@domain.invalid> wrote:
> ** Execute db:load_csv_data
> rake aborted!
> Access denied for user 'root'@'localhost' (using password: NO)

Should it be connecting as root ?

Fred
Sean McGilvray (Guest)
on 2009-03-25 20:59
(Received via mailing list)
No, my database.yml has the correct settings:

production:
  adapter: mysql
  database: DB_NAME
  username: USER_NAME
  password: PASSWORD
  host: 127.0.0.1


Sean McGilvray
Executive Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
removed_email_address@domain.invalid
http://www.transferhome.net


On Wed, Mar 25, 2009 at 11:47 AM, Frederick C. <
Frederick C. (Guest)
on 2009-03-25 21:08
(Received via mailing list)
On Mar 25, 6:58 pm, Sean McGilvray <removed_email_address@domain.invalid> wrote:
> No, my database.yml has the correct settings:
>
which implies that the correct environment isn't loaded. does
RAILS_ENV=production rake db:load_csv_data
work any better?

Fred
Sean McGilvray (Guest)
on 2009-03-25 22:25
(Received via mailing list)
Yes that works.  How do I fix the problem of the correct environment not
loading?


Sean McGilvray & Sarena Byers
Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
removed_email_address@domain.invalid
http://www.transferhome.net


On Wed, Mar 25, 2009 at 12:03 PM, Frederick C. <
Frederick C. (Guest)
on 2009-03-25 23:40
(Received via mailing list)
On Mar 25, 8:24 pm, Sean McGilvray <removed_email_address@domain.invalid> wrote:
> Yes that works.  How do I fix the problem of the correct environment not
> loading?
>
Looks like nothing set the RAILS_ENV environment variable and so it
defaulted to development (things that run apps such as mongrel or
passenger usually have this as an explicit option in the
configuration). You need to  either:
- always specify RAILS_ENV when doing something
- fiddle with the files appropriate to your shell and operating system
so that the environment variable is always set for you.

Fred
Sean McGilvray (Guest)
on 2009-03-26 00:20
(Received via mailing list)
I figured out why this was happening.

I switched to RAILS_ENV='production'

ENV["RAILS_ENV"] has been deprecated.


I did not know that ENV["RAILS_ENV"] has been deprecated.


Thanks for the help.

Sean McGilvray
Executive Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
removed_email_address@domain.invalid
http://www.transferhome.net


On Wed, Mar 25, 2009 at 2:39 PM, Frederick C. <
Maurício L. (Guest)
on 2009-03-26 00:24
(Received via mailing list)
It isn't deprecated, it just not always set, as in the dev
environment, for example.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
Sean McGilvray (Guest)
on 2009-03-26 00:30
(Received via mailing list)
Several post that I have read say that it is deprecated.  When I
switched
from using

ENV['RAILS_ENV'] ||= 'production'

to using

RAILS_ENV='production'

in my environment file my app now loads in production just fine.  When I
was
using ENV['RAILS_ENV'] ||= 'production' it kept coming up in
development.

Sean McGilvray
Execitve Director
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
removed_email_address@domain.invalid
http://www.transferhome.net


2009/3/25 Maurício Linhares <removed_email_address@domain.invalid>
Maurício L. (Guest)
on 2009-03-26 00:51
(Received via mailing list)
I'm not really sure where you saw this, but all of those posts are
clearly wrong.

This is what you're going to find at the rails initializer:

RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless
defined?(RAILS_ENV)

The RAILS_ENV environment variable is where Rails is usually going to
find out at which environment it is (this is specially true at Rake
tasks), your code shouldn't depend on it, as you should get the
current Rails env by doing "Rails.env" (instead of using the constant
as you are), but it is not deprecated. It's just not meant to be used
the way you were trying to.

And instead of using RAILS_ENV, try using Rails.env.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
This topic is locked and can not be replied to.