Forum: Ruby on Rails activerecord connections with xmlrpc

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
mehryar (Guest)
on 2006-02-18 08:34
(Received via mailing list)
Hi folks,

Im trying to use an xmlrpc server and have it serve data using
activerecord, but every request seems to eat up a mysql database
connection, until I run out with "Too many connections". I don't know
enough ruby/rails (or rather ActiveRecord) to figure this one out.

> ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
> rails -v
Rails 1.0.0

code below:
Here is some simplified code exhibiting this behavior:
my server code:
require 'xmlrpc/server'
require 'rubygems'
require_gem 'activerecord'

# a standard user table with name, email, etc
class User < ActiveRecord::Base
                                          :adapter  => "mysql",
                                          # etc. etc.

# given a user id get the user name
def get_username(id)
  u = User.find(id)
  return u.username

s =

s.add_handler("get_username") do |user_id|

s.set_default_handler do |name, *args|
  raise, "Method #{name} missing" +
                                   " or wrong number of parameters!")
client code:
require 'xmlrpc/client'
client ="localhost","/RPC2",8080)
  param ="get_username",123)
  puts "Hello #{param}"
rescue XMLRPC::FaultException => e
  puts "Error:"
  puts e.faultCode
  puts "faultString = [#{e.faultString}]"

"PragDave" had a recent blog on a related note:
but again being a newbie to ruby/rails, my gymnastics with trying to
put the ActiveRecord::Base.establish_connection()
/ ActiveRecord.connection() method in and out of various wrapper
classes/class variables didn't pan out.

This topic is locked and can not be replied to.