kubo / ruby-oci8

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

TNS: no Listener error #150

Closed zmitzie closed 7 years ago

zmitzie commented 7 years ago

I have created a rails 4 app and I'm using the activerecord-oracle_enhanced-adapter to use Oracle as my database. I'm on MacOS and I have installed all the dependencies properly (ruby-oci8, instantclient, etc). I have inserted my database credentials in my database.yml file, but when I run the server I get the following error ORA-12541: TNS:no listener .

I have checked all the similar questions in Stackoverflow but none of them seems to solve my problem. I have also configured a tnsname.ora and listener.ora file under $ORACLE_HOME/network/admin. I am able to connect to the database from the Oracle SQL Developer running in my laptop successfully.

I'm also attaching my Gemfile, database.yml, tnsname.ora and listener.ora files below:

Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.7'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'

gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'ruby-oci8', '~> 2.2.3'

group :development, :test do
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

database.yml:

default: &default
  adapter: oracle_enhanced

development:
  <<: *default
  database: mydb.amazonaws.com/ORCL
  port: 1521
  username: user
  password: pass

listener.ora:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = mydb.amazonaws.com)(PORT = 1521))
    )
  )

tnsname.ora

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = mydb.amazonaws.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = ORCL)
    )
  )

The environment variable TNS_ADMIN points to /opt/oracle/network/admin, where the 2 .ora files are located. I have also edited my hosts file and added my DB's host under 127.0.0.1. I'm using Oracle 12c.

Any help is highly appreciated. Thank you.

kubo commented 7 years ago

Could you connect to the database with sqlplus on your macOS?

$ sqlplus user/pass@mydb.amazonaws.com:1521/ORCL

Could you confirm that your hosts files were edited correctly on your macOS?

$ ping mydb.amazonaws.com

FYI, lister.ora out of the database machine has no effect. tnsnames.ora has no effect if easy connect naming is used.

zmitzie commented 7 years ago

I have resolved the issue https://github.com/rsim/oracle-enhanced/issues/1128

Thanks a lot!

elisbresciani commented 6 years ago

How did you solve the problem? I'm having the same.