kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

OCI8 initialization, trashes the Process::Status #120

Closed govi74 closed 8 years ago

govi74 commented 8 years ago
require 'open3'
require 'pp'
require 'oci8'

def run_command(cmd)
  puts ("Executing command \"#{cmd}\" .")
  status = false
  output = []
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    puts "Wait hr has the value : #{wait_thr}"
    status = wait_thr.value
    while line=stdout.gets
      output << line.chomp
    end

    pp "the value of status : #{status}"

    if status.success?
      puts  ('Successfully executed.')
    else
      puts  ("Command execution failed.")
    end
  end
  [status, output]
end

#this one works fine...
pp run_command('whoami')
puts '-' * 80

# Just initialize the OCI8
ENV['NLS_LANG'] = 'AMERICAN_AMERICA.UTF8'
ENV['ORACLE_SID'] = '+ASM2'
ENV['ORACLE_HOME']='/u01/app/11.2.0/grid'
ENV['LD_LIBRARY_PATH']='/u01/app/11.2.0/grid/lib'
begin
    @asm = OCI8.new('/ as sysasm')
rescue => e
    pp e
end
# Now run the same run_command
pp run_command('whoami') # <<< this errors out

Is this a known issue? Ruby version: ruby-2.3.0 OCI Version: ruby-oci8-2.2.1

kubo commented 8 years ago

This may be same issue with cx_Oracle. https://bitbucket.org/anthony_tuininga/cx_oracle/issues/24/local-database-connect-bug

Could you set the environment variable BEQUEATH_DETACH=YES and try again?

govi74 commented 8 years ago

That was very fast response.. thanks..., but the setting the env variable did not help :-1:

kubo commented 8 years ago

(This comment was updated.)

I tested it. The environment variable doesn't help as you said. But BEQUEATH_DETACH=YES in sqlnet.ora works. I created a file $HOME/.sqlnet.ora containing BEQUEATH_DETACH=YES. The orafaq entry may be incorrect. I deleted statements about the ineffective BEQUEATH_DETACH environment variable in the orafaq entry.

govi74 commented 8 years ago

Thanks a lot, it works and it saved me a lot of time...

Need to set the TNS_ADMIN which points to the sqlnet.ora even before " require 'oci8' "... May be this needs to be documented so, it would be helpful for others.

kubo commented 8 years ago

I added a document. http://www.rubydoc.info/github/kubo/ruby-oci8/file/docs/conflicts-local-connections-and-processes.md