tags:

views:

86

answers:

1

In my ruby script, I set to connect to oracle db via: conn = OCI8.new(username, password, database)

It works well on my own desktop (Ubuntu), however, when I deploy it onto a lab machine (Ubuntu VM), it has oracle connection error. The machine has all oracle drivers needed because I can connect to it by commandline sqlplus. Also I did echo $ORACLE_HOME and it's set correctly. The error is like: env.c:257:in oci8lib.so: ORA-12154: TNS:could not resolve service name (OCIError)

I had the same error on my desktop when ORACLE_HOME was not set correctly. Once I set it right, it started to work. But on this lab machine, although I can launch sqlplus w/o problem, I can't connect via ruby script. Any advice?

+1  A: 

The ORA-12154 error means that the value of the "database" argument in your OCI8.new call is not being found in the tnsnames.ora file that the environment is using. This could be due to:

  • an incorrect value being passed through the variable
  • something in the environment that is pointing to the wrong location for tnsnames.ora. By default it should be in $ORACLE_HOME/network/admin, but this can be overridden by the TNS_ADMIN environment variable.

You say that you can launch sqlplus on the lab machine without any problem, and I assume that this means you can connect to the database of interest when you do this. If this is the case, it seems that the environment present when you run the Ruby script must be somehow different.

dpbradley