7

I am stuck with connecting to Oracle DB, have read lots of stuff but no help on result.
I have remote Oracle DB, I am connecting to it using DBVisualizer setting connection like this:

DB Type : Oracle
Driver (jdbc) : Oracle thin
Database URL: jdbc:oracle:thin:@10.10.100.10:1521/VVV.LOCALDOMAIN
UserIdf: SomeUser
Pass: SomePass

Connection works ok.

What I do in Ruby is :

require 'oci8'
require 'dbi'
...

conn = OCI8.new('SomeUser','SomePass','//10.10.100.10:1521/VVV.LOCALDOMAIN')
...

What I get is:

ORA-12545: Connect failed because target host or object does not exist
oci8.c:360:in oci8lib.so
Nakilon
  • 34,866
  • 14
  • 107
  • 142
qwebek
  • 949
  • 2
  • 8
  • 15

1 Answers1

10

the third parameter needs to be the TNS hostname, if you use SQL plus it is also the third parameter in the connectstring, you can find it also in the tnsnames.ora file in the oracle maps

in SQLPlus : connect user/password@hostname;
in oci8 : conn = OCI8.new('SomeUser','SomePass',hostname)

Here a working sample, obfuscated the parameters of course

require 'oci8'
oci = OCI8.new('****','***','****.***')
oci.exec('select * from table') do |record|
  puts record.join(',')
end
Nakilon
  • 34,866
  • 14
  • 107
  • 142
peter
  • 41,770
  • 5
  • 64
  • 108
  • this not helps ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA – qwebek Mar 30 '12 at 10:44
  • 1
    I have created TNS_ADMIN variable, set my TNS hostname. I can connect through sqlplus and in ruby, I can connect like so oci=OCI8.new('myuser','mypass','//:1521/' BUT When I mention the TNS host, it fails with ORA-12514: TNS:listener does not currently know of service requested in connect descriptor (OCIError) – Nicolas de Fontenay Aug 03 '13 at 00:13
  • 1
    "TNS hostname" isn't a thing. It's called a TNS Alias, and it refers to an entry in the tnsnames.ora file in your $ORACLE_HOME/network/admin directory (this directory is overridden by the TNS_ADMIN environment variable). The hostname, port, and either the SID or the Service Name of the database are defined in the connect descriptor which the OCI looks up with the given Alias. The method @NicolasdeFontenay is using is called EZCONNECT which bypasses the tnsname.ora file by specifying all the details in the string. – Stuporman Sep 10 '16 at 08:30