# Confused about OCI8

**URL:** <https://www.ruby-forum.com/t/confused-about-oci8/129678>\
**Category:** Ruby\
**Created:** [February 20, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678 "2008-02-20T17:21:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 20, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/1 "2008-02-20T17:21:00Z")

</div>

Hi folks,  
I’m studying Ruby converting old Java programs.  
I’m encoutering many difficults connecting to a Oracle 8.0.6 box (say  
responding at 10.0.0.22).  
With Java I simply connect using this infos:

host: 10.0.0.22  
SID: TEST  
username: user  
password: pwd10

and the relative JAR library for Oracle 8.  
With Ruby (version 1.8.6/Win32) I installed the OCI8, then I copied  
the necessary DLL libraries  
from a Oracle/bin directory (such as OCI.DLL) because I don’t have the  
Oracle client on my machine,  
and the Instant client I can download from Oracle’s site is the 11g  
version which doesn’t support Oracle 8.  
So, finally I tried some code.  
First an example from the Oracle’s site:

ruby -r oci8 -e “OCI8.new(‘user’, ‘pwd10’, ‘[//10.0.0.22:1521/](https://10.0.0.22:1521/)  
TEST’).exec(‘SELECT \* FROM test\_table  
WHERE rownum = 1’) do |r| puts r.join(’ | '); end”

But this error occured:

env.c:257:in oci8lib.so: Error while trying to retrieve text for error  
ORA-06401 (OCIError)  
from c:/ruby/lib/ruby/site\_ruby/1.8/oci8.rb:228:in  
`initialize' from -e:1:in `new’  
from -e:1

Second, I tried this other example:

require ‘oci8’

conn = OCI8.new(‘user’, ‘pwd10’, ‘[//10.0.0.22/TEST](https://10.0.0.22/TEST)’)  
cursor = conn.exec(‘SELECT \* FROM test\_table WHERE rownum = 1’)

while r = cursor.fetch()  
puts r.join(‘,’)  
end

cursor.close  
conn.logoff

But this error occured:

env.c:257:in oci8lib.so: Error while trying to retrieve text for  
error ORA-12154 (OCIError)  
from c:/ruby/lib/ruby/site\_ruby/1.8/oci8.rb:228:in  
`initialize' from Test.rb:3:in `new’  
from Test.rb:3

I already look for documentation crawling Google, but it didn’t find  
anything useful.  
Where is my fault?  
Thanks in advance for any suggestion to heal my first Ruby-ache. :o)

Eddy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 4:07am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/2 "2008-02-21T04:07:12Z")

</div>

_TNS-12154 TNS:could not resolve service name._

Can you connect to the Oracle 8 db using sqlplus with this connection  
string  
'[//10.0.0.22/TEST](https://10.0.0.22/TEST)"? The service\_name of the db is “TEST”?

2008/2/21, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 9:21am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/3 "2008-02-21T09:21:15Z")

</div>

In the meanshile I added this to the TNSNAMES.ORA  
on a machine with SQLPlus:

TEST =  
(DESCRIPTION =  
(ADDRESS\_LIST =  
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.22)(PORT = 1521))  
)  
(CONNECT\_DATA =  
(SERVICE\_NAME = TEST)  
)  
)

Using “TEST” as connection string, SQLPlus works.  
But, using OCI8, how can I use the TNSNAMES.ORA?  
Thanks in advance for any help to solve this doubt,

Eddy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 9:01am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/4 "2008-02-21T09:01:03Z")

</div>

No, I cannot connect using the string [//10.0.0.22/TEST](https://10.0.0.22/TEST).  
Maybe I’m understanding: OCI8 uses the SQLPlus approach for  
connections to the DB,  
which is different from JDBC. Am I right or not?  
So, could it be a DB configuration problem? If I’m able to connect  
with SQLPlus  
I’m able to connect with OCI8?  
Best regards,

Eddy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 11:00am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/5 "2008-02-21T11:00:52Z")

</div>

OK,  
to summarize:

1. I have to install the full version of Oracle client
2. I have to add the service name to TNSNAMES.ORA
3. To test the connection I will use OCI8.new("", “”,  
“\<service\_name\>”)  
So, with Oracle 8 and 9, I cannot use the Instant client 10.x because  
I can only use the ///\<service\_name\> form only with 10g  
database.  
Is it all right?  
Thanks,

Eddy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 10:13am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/6 "2008-02-21T10:13:46Z")

</div>

Hi,

On Thu, Feb 21, 2008 at 1:20 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> With Ruby (version 1.8.6/Win32) I installed the OCI8, then I copied  
> the necessary DLL libraries  
> from a Oracle/bin directory (such as OCI.DLL) because I don’t have the  
> Oracle client on my machine,  
> and the Instant client I can download from Oracle’s site is the 11g  
> version which doesn’t support Oracle 8.

Full client’s OCI.DLL won’t work if it is copied to outside the  
installed  
directory. You need to install the Oracle client on your machine.  
It may work by copying all files under ORACLE\_HOME and all  
registry keys under \HKEY\_LOCAL\_MACHINE\SOFTWARE\ORACLE.  
But I’m not sure that is all.

> So, finally I tried some code.  
> First an example from the Oracle’s site:
> 
> ruby -r oci8 -e “OCI8.new(‘user’, ‘pwd10’, ‘[//10.0.0.22:1521/](https://10.0.0.22:1521/)  
> TEST’).exec(‘SELECT \* FROM test\_table  
> WHERE rownum = 1’) do |r| puts r.join(’ | '); end”

‘[//10.0.0.22:1521/TEST](https://10.0.0.22:1521/TEST)’ is a new feature of Oracle 10g.  
It won’t work on older Oracle versions.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/7 "2008-02-21T14:42:20Z")

</div>

OK,  
all work, finally! :o)  
I installed the Oracle client 9.2 on my machine, then configured  
the TNSNAMES.ORA with the right service name, and both SQL\*Plus  
and my Ruby test app work.  
Thanks a lot for your support Kubo, and thanks to Jesse for the first  
important suggestion.  
Best regards,

Eddy

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 21, 2008, 11:26am UTC](https://www.ruby-forum.com/t/confused-about-oci8/129678/8 "2008-02-21T11:26:11Z")

</div>

HI,

On Thu, Feb 21, 2008 at 6:59 PM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> OK,  
> to summarize:
> 
> 1. I have to install the full version of Oracle client

Yes.

> 1. I have to add the service name to TNSNAMES.ORA

Yes.

> 1. To test the connection I will use OCI8.new(“”, “”,  
> “\<service\_name\>”)

1. To test the connection I will use OCI8.new(“”, “”,  
“\<tns\_name\>”)

\<tns\_name\> is a name defined in TNSNAMES.ORA.  
Tns name may be differnet name with service name.

> So, with Oracle 8 and 9, I cannot use the Instant client 10.x because  
> I can only use the ///\<service\_name\> form only with 10g  
> database.

10g client, exactly speaking.  
10g client can use ///\<service\_name\> to connect to 9i databases.
