For one of my projects I need to use an Oracle database on a Rails app.
For my local development, I've installed Oracle VM VirtualBox with the package Oracle Developer Day . I successfully deployed, launched the VM, logged in and even created a user on SQLPlus with admin rights.
On my mac OSX Mavericks, I've installed instant client from Oracle as well as the following version of ruby-oci8 and activerecord-oracle_enhanced-adapter
gem ruby-oci8', '~> 2.0.6'
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.1'
My config file for my dev database is the following database.yml
development:
adapter: oracle_enhanced
host: 192.168.2.170:1521/myprogram_development
username: my_new_sql_plus_username
password: my_new_sql_plus_password
On Oracle VM side, I've set up my network as the screenshot shows
When I connect my VM I have the same IP as the database.yml file above
All that looks fine (I've followed every steps of this tutorial and also tried this one ), but when I try my rake db:setup
command or to access the db via OCI8.new("my_new_sql_plus_username", "my_new_sql_plus_password", "//192.168.2.170:1521:1521/orcl")
, I have the following error message.
rake aborted!
ORA-12170: TNS:Connect timeout occurred
oci8.c:267:in oci8lib_191.bundle
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:326:in `new'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:326:in `new_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:436:in `initialize'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `new'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `initialize'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in `new'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in `create'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb:13:in `oracle_enhanced_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.4.3/lib/active_record/connection_adapters/oracle_enhanced.rake:26:in `create_database_with_oracle_enhanced'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:62:in `each'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.14/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/Users/stephanethomas/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:setup => db:schema:load_if_ruby => db:create
Thanks in advance for your help
I figured it out. So couple of problems: First the network config. Use Bridged adapter instead of NAT, like below
Second, the config file in the rails app (database.yml), don't forget the 2 slashes in front of the IP ...
development:
adapter: oracle_enhanced
host: //192.168.2.170:1521/myprogram_development
username: my_new_sql_plus_username
password: my_new_sql_plus_password
And it's all good !