2

这是一个 ruby​​ 项目,使用 ActiveRecord 的 oracle-enhanced-adapter gem 连接到 Oracle。这个 gem 是 OCI8 的包装器。

ActiveRecord::Base.establish_connection(
    :adapter => "oracle_enhanced", 
    :database => "xxx.xxx.xxx.xxx:1521/nnnn",
    :username => "some_user_name",
    :password => "very_secret_password"
)
ActiveRecord::Base.pluralize_table_names = false

class All_tables < ActiveRecord::Base
end

好的,让我们测试一下。

[1] pry(main)> All_tables.take
OCIError: ORA-12545: Connect failed because target host or object does not exist
from oci8.c:513:in oci8lib_200.so

给它 5 秒钟,然后再试一次。

[2] pry(main)> All_tables.take
#<All_tables owner: "SYS", table_name: "DUAL", tablespace_name: "SYSTEM",....

这种解决方法可以完成工作,但感觉有点脏。

retrylimit=5
begin
  All_tables.take
rescue
  sleep 2
  puts "retrying"
  retrylimit -= 1
  retry if retrylimit > 0
end

看起来像一个经典的超时,但是......如果它是一个超时,我可以在哪里以及如何配置它?注意:已经在建立连接中尝试过 :timeout => 5000。没用。

4

1 回答 1

0

I'm assuming xxx.xxx.xxx.xxx is a host name. Check the DNS configuration on the ActiveRecord machine. Try using nslookup and ping to diagnose why - sometimes - the remote machine name cannot be resolved. It's also possible that the name resolution is too slow for OCI, so it is failing on first attempt. Then the resolution is cached the next attempt succeeds. Try using an IP address instead.

Enable SQL*Net tracing for the Oracle client. That may provide enough information to positively answer your question.

于 2014-02-13T15:35:54.837 回答