views:

239

answers:

3

I went through all the steps described here to set up my OS X machine to allow me to connect to Oracle from a Rails app.

Set up the database.yml file in my app:

development:
  adapter: oracle_enhanced
  host: [SERVER IP ADDRESS]
  database: [ORACLE INSTANCE SID]
  username: xxx
  password: yyy
  encoding: utf8

Also tried it with the domain name.

Tried in Rails console...

>> con = ActiveRecord::Base.connection

But it hung for a long time then timed out with the error...

OCIError: ORA-12170: TNS:Connect timeout occurred
    from env.c:257:in oci8lib.so
    from /usr/local/lib/ruby/site_ruby/1.8/oci8.rb:229:in `initialize'
    from /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.0/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:184:in `new'
    from /usr/local/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.0/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:184:in `new_connection'

[...]

Has anyone gotten this working on OS X and knows how to solve this?

+1  A: 

If you have sqlplus installed with your Oracle client software, you should try connecting with that first to make sure the problem is your Rails config and not your connection info or the server itself.

jiggy
A: 

You should have either the host: line or the database: line, but not both.

Use the database: line if you have a TNS entry.

database: orcl    ## orcl is an entry in tnsnames.ora

Otherwise use the host: format.

host: dbhost.example.com/orcl    # dbhost: network address of the database host
                                 # orcl: database instance name

More notes here:

http://stackoverflow.com/questions/764887/how-to-configure-ruby-on-rails-with-oracle

Mark Harrison
A: 

I am having this working :
-------------------------------------------------------------------
conn = OCI8.new('casserver', '*', '10.xxx.xx.xx:1521/xxxDB')
conn.exec('select 1 from dual ') do |r|
puts r
end
conn.exec('select id from casserver_schema_infos ') do |i|
puts i
end
-------------------------------------------------------------------
But not this one (in the config.yml) :
-------------------------------------------------------------------
database:
adapter: oracle
username: casserver
password: *
host: 10.xxx.xx.xx:1521/xxxDB
# host: 10.xxx.xx.xx:1521
# database: xxxDB
# encoding: utf8
-------------------------------------------------------------------
Tried Separately as well, but doesn't work.
------------------------------------------------------------------
It gives the following Error
Initialized global logger to "/var/log/casserver.log".
env.c:257:in oci8lib.so: ORA-12162: TNS:net service name is incorrectly specified (OCIError)
from /opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/oci8.rb:229:in `initialize' from /opt/rubygems/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:623:in `new'
from /opt/rubygems/gems/activerecord-oracle-adapter-1.0.0.9250/lib/active_record/connection_adapters/oracle_adapter.rb:623:in `new_connection'


Can Any One please help ?

------------

Suresh