connecting to remote oracle via cygwin sqlplus - oracle

I'm trying to use cygwin sqlplus to connect to a remote oracle installation located at myserver.mycompany.com port 1530. When I try
sqlplus username#myserver.mycompany.com:1530/orcl
I get the error:
ORA-12154: TNS:could not resolve the connect identifier specified
When I set ORACLE_HOME to /cygdrive/c/oracle/product/10.2.0/client_1, I get a different error:
Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
I can telnet to the server's port 1530, and the SQL Developer installed locally is also able to connect to the database. What am I doing wrong?

I wasn't aware there was a native cygwin client for Oracle (correct me if I'm wrong here but I can't find any mention of it on Oracle's web site either). If you're using Cygwin with the Windows client you need to use a native windows path. It won't understand your /cygdrive path.
However, I have used Win32 Oracle clients with cygwin and made it work - the same shell scripts would work on Cygwin, Linux and Solaris.

There isn't a cygwin Oracle client. As above answer, use the ORACLE_HOME set to the windows path.
For the first half of your question, try seeing what the TNS_NAMES env variable is set to, and if not set, you may need to try setting it to the correct place. Usually it defaults to %ORACLE_HOME%/network/admin/tnsnames.ora . SQL Developer keeps it's own copy of the tnsnames file, so you can't reply upon that to fix the problem.

Combining the details from the other answers (which took me a little, so I post it as separate answer instead of comments):
The $ORACLE_SID and, if set, $TNS_ADMIN (and probably other path-related Oracle variables) must use Windows-paths. Your Cygwin $PATH variable should of course use the Cygwin notation (/drives/c/…). So I've included into my .bashrc:
export ORACLE_HOME=c:\\Oracle\\product\\12.1.0\\dbhome_1
export TNS_ADMIN=d:\\Oracle\TNSAdmin
export PATH=$PATH:$(cygpath -u $ORACLE_HOME)/BIN
After that, I had no more issues calling e.g. tnsping or sqlplus. As the above is just an example, you must of course adjust the paths to reflect your installation/configuration :)

NXC is right - it wasn't a cygwin client I was using, but the windows sqlplus client.
I set the windows environment variables for ORACLE_HOME and ORACLE_SID and was then able to run sqlplus in a cygwin bash shell using the net_service_name from tnsnames.ora.

The way it worked for me was to remove /cygdrive/d or /cygdrive/c and replace them with with d:/ or c:/ and then your sqlplus call within cygwin session will work. The /cygdrive/DriveLetter is confusing it.

I have same error like you,
you should set not only ORACLE_HOME in windows Variables,
But also PATH include %ORACLE_HOME%\bin
then you can open windows cmd,
try sqlplus username/password#your_define_tnsname
if okay, then remove all ORACLE PATH setting in cygwin, restart cygwin,try it.
if failure, should let sqlplus works well in windows cmd at first

I have TNS_ADMIN variable configured and it works properly in Win Environ
I used cygpath mnodification in .bashrc
If TNS_ADMIN is configured add following row to .bashrc
export TNS_ADMIN=$(cygpath -m $TNS_ADMIN)

Related

expdp command gives error on Ubuntu server for Oracle Database

I've been trying to export oracle datadump with "expdp" utility in Oracle 18c. I've set the environment variables under ~/.bashrc as following
export ORACLE_HOME=/home/ubuntu/oracle-database-xe-18c-1.0/opt/oracle/product/18c/dbhomeXE
export ORACLE_SID=ORCL
export ORACLE_BASE=/home/ubuntu/oracle-database-xe-18c-1.0/opt/oracle/product
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin
When I enter the command "expdp" in terminal - it keep saying your ORACLE_HOME is not set
root#ip-172-30-xx-xxx:~# expdp
UDE-00013: Message 13 not found; No message file for product=RDBMS, facility=UDE
UDE-00019: You may need to set ORACLE_HOME to your Oracle software directory
I'm new to Oracle Database at present. What could be the possible issue ? Do I need to set environment variables at some other places too ?
Note that Oracle XE is not really supported on Ubuntu: if you really want to use Oracle, install it on Oracle Linux (freely available): you will never see Oracle Database running in real production on Debian or Ubuntu and you will need to use Oracle Linux or RedHat Linux or Suse Linux.
Do not run Oracle utilities as root: you don't need to and it is generally a bad practice on Linux to use root account when it is not needed. Use a non privileged account to run Oracle utilities like SQL*Plus or Data Pump and make sure that your Oracle settings are run for each shell session: putting them in .bash_profile for the right account should be enough.
For this specific error message just make sure that ORACLE_HOME is correctly set: it is likely that your .bashrc has not been run.

trying to connect to remote oracle server via cygwin

When I use the command:
sqlplus username#ip_address:1521
I get the error:
ORA-12154: TNS:could not resolve the connect identifier specified
When I set ORACLE_HOME to /cygdrive/c/oracle/product/10.2.0/client_1, I get a different error:
Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
I can telnet to the server's port 1521.
I also tried the Windows path for ORACLE_HOME but it gives me the same error, also in Cygwin when I change the $PATH = $ORACLE_HOME/bin no command is recognized.
I am able to connect to this database via a excel macro but not using cmd.exe or Cygwin .
If you don't want to use TNSNAMES.ORA to specify the connection parameters you need to provide them on the command line. This works with the widest variety of SQLPlus versions.
sqlplus OraUser/OraPassword#'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=remoteServer)(PORT=1521)))(CONNECT_DATA=(SID=OraSid)))'
Note ' is for Unix and needs to be changed to " for Windows.

ora-12154 could not resolve... with oracle instant client

Here are the details:
I installed the oracle instant client 11.2.0.2.0 from the OTN download page on a windows 7 64 bit vm (vmware).
I am trying to to connect to a remote oracle database, and I can successfully connect with one program using TNS, but not with SQL*Plus and other applications.
Trying to connect with SQL*Plus, using schema#servicename, password, etc, gives the above error.
To connect via SQL Developer, normally I would use the basic connection info and not rely on tnsnames, but trying a normal connection gives me: io error: unknown host specified. SQL Developer can successfully connect and query database if i use the TNS protocol.
Trying from other programs gives me the same error I got with SQL*Plus. Same when trying with the service name from tnsnames.
This is obviously quite frustrating for it to work one way and not the other. I followed all the normal instructions for using the instant client, the directory with instantclient has been addded to the PATH, a TNS_ADMIN entry has also been created, with the directory to the tnsnames.ora file
Well, on a whim, I went to changing everything in my setup to match an windows 2003 server that i had setup with instant client before. The main changes were putting the instant client in a folder at the root of the drive (not program files/oracle/etc), but c:/oracle, i know ive seen other posts saying that oracle was particular about characters in the directory path, maybe spaces are a no-no too?
I also add a bunch more environmental variables, anythign that was on the other machine, ORACLE_HOME (to root of instance), SQL_PATH (same), and added the root of the directory to the PATH system variable, not just the folder with the instantclient files. Anyways, I'm happy its working, anyone one of these changes could have been it though-
You may use ProcessMonitor and look at what your sqlplus process is doing. In my case TNS_ADMIN was correctly defined but, by mistake, my tnsnames.ora and sqlnet.ora had a stupid ".txt" extension, added by default by notepad when I created those files. And because "Windows Explorer" has the "Hide extensions for known file types" option set by default, the naming error wasn't obvious at all.
I installed the 12.1 instant client. For me, the problem was solved by creating \network\admin\tnsnames.ora file. Here's the PowerShell I used:
$source = "C:\Users\USER1\Desktop\tnsnames.ora"
$target = "C:\oracle\product\12.1.0\client_1\network\admin"
mkdir $target
copy-item $source $target

Oracle connectivity in Ruby

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?
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.

Oracle Pro*C ORA-12547

I'm working on re-compiling some Pro*C code that no one currently at my company has ever compiled. It's compiling OK, but when I copy it to the production server and run it I'm getting Oracle error ORA-12547 (TNS: lost contact)
Any ideas?
Oh, figured it out. :-)
The C executable isn't run directly on the server, but launched through a script that sets up the connection environment. i.e. something like this:
export SHLIB_PATH=/oracleDatabaseSidHere/oracle/10.2/lib:/usr/lib:/oracleDatabaseSidHere/oracle/10.2/odg/lib
export ORACLE_BASE=/oracleDatabaseSidHere/oracle
export ORACLE_SID=oracleDatabaseSidHere
export ORACLE_HOME=/oracleDatabaseSidHere/oracle/10.2
# Set up the path and executable to run
PATH=.\:$PATH:$ORACLE_HOME/bin:/usrlocal/bin
PATH=$PATH:/path_to_application_logs
cd /path_to_application
application
Related to this, I just found out that I get the same error ORA-12547 TNS lost contact on my Windows machine when I try to connect to an Oracle database with PL/SQL and at the same time I have a VPN connection open.
I had a similar problem on Linux, Oracle 11gR2. Oracle owner could run SQL*Plus and get in via either TNS or local connection. Non-oracle user could log in via TNS, but not as local connection.
Turns out the answer was that the ORACLE_HOME filesystem was mounted "nosuid". Removing that mount option solved my issue.

Resources