Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > ActiveRecord without Rails: necessary to close connection?

Reply
Thread Tools

ActiveRecord without Rails: necessary to close connection?

 
 
Mischa Berger
Guest
Posts: n/a
 
      04-15-2009
Hello everyone,

This is the first time I want to use ActiveRecord outside Rails. This is
my (simplified) code:

ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'username',
assword => 'password',
:database => 'database')

class Rate < ActiveRecord::Base
end

r = Rate.find(:first)
r.value = new_rate
r.save!

This works fine, but I was wondering if I have to close any database
connections at the end of my script (by using remove_connection??)? Or
is does AR take care of this automatically?

Thanks in advance.

Mischa.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Brian Candler
Guest
Posts: n/a
 
      04-15-2009
Mischa Berger wrote:
> This works fine, but I was wondering if I have to close any database
> connections at the end of my script (by using remove_connection??)? Or
> is does AR take care of this automatically?


Don't bother. The operating system will close all open filehandles when
the process terminates.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Mischa Berger
Guest
Posts: n/a
 
      04-15-2009
Brian Candler wrote:
> Don't bother. The operating system will close all open filehandles when
> the process terminates.


Thanks. With the same script I have another issue. When I execute the
script from the command line it runs flawlessly, but when it's executed
from cron I get the following error in my script: no such file to load
-- mysql

The line where the error occurs is:
r = Rate.find(:first)

My crontab looks like this:
* * * * * /usr/local/bin/ruby
/home/mischa/railsapps/aexscript/periodic/get_rate.rb production >>
/home/mischa/railsapps/aexscript/periodic/get_rate.log

So I use full path to everything.

Any ideas??

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Mischa Berger
Guest
Posts: n/a
 
      04-15-2009
I got it working. It turned out the mysql gem wasn't in the expected gem
folder. Why everything works smoothly from the command line is beyond
me, but it works
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
ActiveRecord/Oracle without Rails Drew Olson Ruby 9 08-26-2008 03:06 AM
ActiveRecord without Rails Ari Brown Ruby 4 07-31-2007 07:30 PM
Self.close() window without the dialog close?Yes/NO Walter Beierdonck Javascript 1 04-30-2004 02:48 PM
How to close child browser while parent close? Denon ASP .Net 1 11-14-2003 08:14 AM



Advertisments