RubyOnRails multiple database connections errors

80 views Asked by At

I have a rails application (ruby 2.0.0, Rails 4.0.1) that connects to several MySQL database. The connection to the local database always work properly, this is my configuration:

 production:
  adapter: mysql
  encoding: utf8
  database: xxx
  username: yyy
  password: zzz
  host: x.x.x.x
  port: 3306
  reconnect: true

But connections to remote databases often return an error, such as connecting to my radius external database returns the following error:

Mysql :: Error:: SELECT 1 AS one FROM WHERE `` radacct` radacct`.`username` =? LIMIT 1

Updating the page several times, the connection is restored and I can see the data properly. This is my configuration:

 radius:
  port: 3306
  adapter: mysql
  encoding: utf8
  database: xxx
  username: yyy
  password: zzz
  host: x.x.x.x
  reconnect: true
  connect_timeout: 60
  read_timeout: 90
  write_timeout: 90
  checkout_timeout: 10
  reaping_frequency: 30
  dead_connection_timeout: 30

I tried to change the configuration of the timers in different ways, but the problem persists.

to connect to the radius server I created the following model common to all:

class RadActiveRecord <ActiveRecord :: Base
   self.abstract_class = true
   establish_connection "radius"
end

for example for the table radacct use the following model:

class RadAcctDetail <RadActiveRecord
   self.table_name = "radacct"
end

the error in question is with any queries, such as:

def index
     @rad_acct_details = RadAcctDetail.all.paginate = (
       : order => "radacctid DESC"
       : page => params [: page] || 1
       : per_page => params [: per_page] || 25)
end

Does anyone have any suggestions?

0

There are 0 answers