Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"
Posted
Updated 19-Jul-20 0:04am

1 solution

First off, with the error you get, it is not related to Rails here. It's plain simple error related to Oracle that indicates something wrong with the database connection.

Now, given the error code, seems handful of information on web/Google for it:
Refer: How to resolve Oracle errors - Troubleshooting[^]
Quote:
If you run the converter on 64-bit Windows, the most probable reason of the error is that executable module has been placed into folder "C:\Program Files (x86)\..." while Oracle does not allow quotes symbols in client application. In order to fix the error, copy all contents of product's installation folder into another location that does not contain quotes in the path.

Similar query answered here at CodeProject with few more variations, you can try if above does not work: ORA-06413: Connection not open[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900