Greetings! I am trying to use ActiveRecord in a non-Rails script to
access a database, but I'm not doing something right apparently:
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host => "myhost.org",
:port => 1234,
:username => "myuser",
:password => "mypass",
:database => "mydb"
)
conn = ActiveRecord::Base.connection
puts conn.active?
When I try to run this code, I get an exception when trying to
retrieve the connection:
:~/ruby$ ruby activerecordtest.rb
/usr/lib/ruby/1.8/readbytes.rb:23:in `readbytes': End of file reached
(EOFError)
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/message.rb:32:in `read'
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/connection.rb:30:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/connection.rb:29:in `loop'
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/connection.rb:29:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/postgres-compat.rb:23:in `new'
from /usr/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/
postgres-pr/postgres-compat.rb:23:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/postgresql_adapter.rb:24:in
`connect'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/postgresql_adapter.rb:24:in
`postgresql_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/connection_specification.rb:
262:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/connection_specification.rb:
262:in `connection_without_query_cache='
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/query_cache.rb:54:in `connection='
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/connection_specification.rb:
230:in `retrieve_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/abstract/connection_specification.rb:
78:in `connection'
from activerecordtest.rb:13
Anyone have any ideas why this isn't working?
Thanks!