I'm pretty new in rails. I've a problem with Oracle. I always get ORA-06413: Connection not open error from oracle when I run the rails server
I'm using this configuration
ruby '2.6.3'
gem 'rails', '~> 5.2.3'
gem 'pg', '= 0.18.1'
gem 'ruby-oci8', '~> 2.2.4'
gem 'activerecord-oracle_enhanced-adapter','~> 5.2.3'
...
My database.yml is
oracle_db:
adapter: oracle_enhanced
database: //192.168.0.2:1521/PRODUCTION
username: username
password: password
development:
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
adapter: postgresql
encoding: unicode
username: username
password: password
host: 192.168.0.3
database: my_db
I'm wrote this class to retrieve last person code insered in oracle DB
class Oracle < ActiveRecord::Base
establish_connection :oracle_db
scope :open, -> { where(FIELD: 'FC').order(created_at: :desc) }
def self.GetLastPersonCode
myquery = "SELECT CODE FROM table WHERE ROWNUM = 1 ORDER BY CODE DESC"
result = self.connection.select_one(myquery)
if result["code"].nil?
codice = "NEW200000"
else
record = result["code"].to_s.strip
code = "NEW"+(record[3..].to_i+1).to_s
end
return code
end
end
When I insert a new person in my PG database I want to find last code in oracle_db and create a new one. I'm using this code
@person = Person.new(person_params_post)
@person.code = Oracle.GetLastPersonCode
@person.save
Now, all works fine But when I try to recover the code I get the error 'ORA-06413: Connection not open'. The thing that I don't explain is that... if from rails console I launch the Oracle.GetLastPersonCode I correctly recover the person code. I'm using visual studio code on Debian Buster.
What change between server and console environment?
What I have tried:
Rails console
Loading development environment (Rails 5.2.4.1)
2.6.3 :001 > Oracle.GetLastPersonCode
(1163.3ms) SELECT ....WHERE ROWNUM = 1
=> "CFC192957"