Database Error?

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

Should it be connecting as root ?

Fred

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 smcgilvray@prepaidlegal.com http://www.transferhome.net

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

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 smcgilvray@prepaidlegal.com http://www.transferhome.net

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

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 smcgilvray@prepaidlegal.com

http://www.transferhome.net

It isn't deprecated, it just not always set, as in the dev environment, for example.

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 smcgilvray@prepaidlegal.com http://www.transferhome.net

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.