简体   繁体   中英

Set database connection timeout in rails

I am using activerecord-oracle_enhanced-enhanced (1.6.6) gem to connect with the oracle database from the rails app (rails 4.2.5)
I need to set the Database connection timeout.
Below are the setting used in database.yml file,

development:  
    adapter: oracle_enhanced  
    host: 10.10.10.58  
    port: 1521  
    database: TUTSDB  
    username: tutsadmin  
    password: Tuts1234  
    encoding: utf8  
    timeout: 15000  

I have specified the timeout to be 15 sec.
Even after doing this we are getting the below error:
(ActiveRecord::ConnectionTimeoutError) "could not obtain a database connection within 5 seconds (waited 5.000144774 seconds) .
It is waiting for the connection only for 5 seconds (which is the default timeout value). Ideally it should wait for 15 sec.

Looking at the Timeouts guides it seems that you have to set the timeout otherwise:

development:
  database: "(DESCRIPTION=
    (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    (CONNECT_TIMEOUT=5)(TCP_CONNECT_TIMEOUT=5)
    (CONNECT_DATA=(SERVICE_NAME=xe))
  )"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM