I am unable to connect to oracle database using jdbc.
Error:
Could not connect to database at jdbc:oracle:thin:#localhost.localdomain:1521:orcl (Username: system, Password: tiger)
However, I can connect it using sqlplus command.
Here is the log:
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
Version = Sun GlassFish Enterprise Server v2.1
Testing Database Connection ...
-- Failure! java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
Here is the listener.ora:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /home/oracle/app/oracle
Output of lsnrctl:
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=::1)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
Contents of tnsnames.ora:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
I am using Oracle 11g, glassfish server 2.1, Redhat linux enterprise edition 6.
Any help would be really appreciated.
--Sam
Try replacing localhost.localdomain with localhost in the connection string, i.e.
jdbc:oracle:thin:#localhost:1521:orcl
I too get a The Network Adapter could not establish the connection error if I use localhost.localdomain as the address, and it goes away if I use just localhost.
Test :
telnet localhost 1521
and if it does not work
Set iptables :
https://exploringspatial.wordpress.com/2013/06/08/installing-oracle-sql-developer/
Related
I have installed oracle database and oracle sql developer. When I try to connect I am getting the below error
Status: Failure -Test failed: Listener refused the connection with the following error:
ORA-12505, TNS: listener does not currently know of SID given in connect descriptor
(CONNECTION_ID=E2rGqMoxSoqYb2fJOCTRbw==)
transnames.orc
# tnsnames.ora Network Configuration File:
C:\app\Faisal\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
listner.ora
# listener.ora Network Configuration File:
C:\app\Faisal\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\Faisal\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\app\Faisal\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = C:\app\Faisal
NET Manager
CMD
C:\WINDOWS\system32>lsnrctl status
LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Production on 03-JUN-2022 17:33:53
Copyright (c) 1991, 2010, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1522)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
64-bit Windows Error: 2: No such file or directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Production
Start Date 03-JUN-2022 17:04:13
Uptime 0 days 0 hr. 29 min. 39 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File D:\app\Faisal\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File d:\app\faisal\diag\tnslsnr\Faisal\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 3 handler(s) for this service...
Service "sd" has 1 instance(s).
Instance "sd", status READY, has 1 handler(s) for this service...
Service "sdXDB" has 1 instance(s).
Instance "sd", status READY, has 1 handler(s) for this service...
The command completed successfully
Any help would be highly appreciated
Make sure:
1- the listener is started
2- provide correct SID or Service Name: meaning, if these 2 are different dont use the name of the SID while checking the Service Name checkbox.
3-make sure you have the ping of the server you are reaching (direct access, if not do the tunneling)
4- make sure you are using the correct port
5- make sure you are not using PDB and you have created your own database! (PDBs always go south)
These are the reasons you see that error
I have RHEL 6.8 Oracle version on Azure on which I installed database following Microsoft's tutorial Create an Oracle Database in an Azure VMe. Everything went fine with the tutorial. Now I try to install APEX with this one Oracle Application Express (APEX) 5.x Installation and I am stuck at line CONN sys#pdb1 AS SYSDBA.
After entering a password (doesn't matter if it is correct) I get every time ERROR: ORA-12154: TNS:could not resolve the connect identifier specified.
I have already tried:
Creating variable TNS_ADMIN
Adding ORACLE_HOME/network/admin to PATH
Creating and editing files:
listener.ora:
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
sqlnet.ora:
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)
tnsnames.ora:
WINDOWNETSERVICE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cdb1)
)
)
Output of lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 26-JUL-2017 09:02:06
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=OracleDbVm)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 25-JUL-2017 23:19:33
Uptime 0 days 9 hr. 42 min. 32 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/OracleDbVm/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=OracleDbVm.{some_values}.ax.internal.cloudapp.net)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=OracleDbVm.{some_values}.ax.internal.cloudapp.net)(PORT=5502))(Security=(my_wallet_directory=/u01/app/oracle/product/12.1.0/dbhome_1/admin/cdb1/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "cdb1" has 1 instance(s).
Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "cdb1XDB" has 1 instance(s).
Instance "cdb1", status READY, has 1 handler(s) for this service...
Service "pdb1" has 1 instance(s).
Instance "cdb1", status READY, has 1 handler(s) for this service...
The command completed successfully
Output of my env:
[oracle#OracleDbVm admin]$ env
HOSTNAME=OracleDbVm
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
OLDPWD=/home/oracle
USER=oracle
LS_COLORS={colors_long_values}
ORACLE_SID=cdb1
TNS_ADMIN=/u01/app/oracle/product/12.1.0/dbhome_1/network/admin
MAIL=/var/spool/mail/oracle
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/u01/app/oracle/product/12.1.0/dbhome_1/network/admin:/u01/app/oracle/product/12.1.0/dbhome_1/bin:/home/oracle/bin
PWD=/u01/app/oracle/product/12.1.0/dbhome_1/network/admin
LANG=en_US.UTF-8
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HISTCONTROL=ignoredups
SHLVL=1
HOME=/home/oracle
LOGNAME=oracle
LESSOPEN=||/usr/bin/lesspipe.sh %s
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
G_BROKEN_FILENAMES=1
_=/bin/env
What can I do more to fix that problem?
Your CONN sys#pdb1 AS SYSDBA is trying to connect to an instance with a SID (or tnsnames entry) of pdb1, but in a multitenant environment all your databases share the same SID (cdb1 in your case), and you don't have a pdb1 entry in your tnsnames. When connecting to a PDB, you need to use the service name in the connect string.
You can either update your tnsnames like this:
WINDOWNETSERVICE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = OracleDbVm)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cdb1)
)
)
pdb1=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=OracleDbVm)
(PORT=1521)
)
(CONNECT_DATA=
(SERVICE_NAME=pdb1)
)
)
And then try CONN sys#pdb1 AS SYSDBA again...
Or you can try using a full connect string with the service name, like:
conn sys#OracleDbVm:1521/pdb1 as sysdba
I think you could also connect to the CDB, switch to pdb1, and then start the script. Let me know if you want more details on that option.
i was started Oracle listener,but it was started with status unknown
due to this i'm not able to connect connect with SQL Developer Tool
it showing error like
Status : Failure -test failed: IO Error : The Network Adaptor could not establist the connection
if i started listener it shows as follows
Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/xe/network /admin /listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/ist-354/listener /alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ist- 354)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 06-NOV-2016 15:31:30
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin /listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ist-354/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ist-354)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
my listener.ora
# listener.ora Network Configuration File:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = ist-354)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
tnsnames.ora
# tnsnames.ora Network Configuration File:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ist-354)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
Please follow this steps,
turn your listener on.
Try "tnsping XE" from ist-354 host.
if you can successfully connect using TNS then you firewall is causing this. please check if fire wall is running.
you can have help turning off firewall from this link,
http://www.cyberciti.biz/faq/fedora-redhat-centos-5-6-disable-firewall/
I have oracle 11g XE everything running well except that I can't connect to oracle via SQLplus client from remote mashine.
My server running centos with oracle 11g XE.
My listener.ora file looks like:
cat /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
listener.ora Network Configuration File:
SID_LIST_LISTENER = (SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
) )
LISTENER = (DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = servername.domain.com)(PORT = 1521))
) )
DEFAULT_SERVICE_LISTENER = (XE)
My tnsnames.ora looks like:
XE = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
) )
EXTPROC_CONNECTION_DATA = (DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
) )
ORACLR_CONNECTION_DATA = (DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
) )
lsnrctl status shows:
-bash-4.1$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 21-MAR-2014
14:00:28
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to
(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE))) STATUS of
the LISTENER
------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production Start Date
21-MAR-2014 13:39:10 Uptime 0 days 0 hr. 21 min. 18
sec Trace Level off Security ON: Local
OS Authentication SNMP OFF Default Service
XE Listener Parameter File
/u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora Listener
Log File
/u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/venera/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=servername.domain.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=servername.domain.com)(PORT=8080))(Presentation=HTTP)(Session=RAW))
Services Summary... Service "PLSExtProc" has 1 instance(s). Instance
"PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s). Instance "XE", status READY, has 1
handler(s) for this service... Service "XEXDB" has 1 instance(s).
Instance "XE", status READY, has 1 handler(s) for this service... The
command completed successfully
File /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/venera/listener/alert/log.xml when I try to connect:
21-MAR-2014 14:00:03 * service_update * XE * 0
WARNING: Subscription for node down event still pending
21-MAR-2014 14:00:28 *
(CONNECT_DATA=(CID=(PROGRAM=)(HOST=servername.domain.com)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=186647040))
* status * 0
21-MAR-2014 14:00:33 * service_update * XE * 0
21-MAR-2014 14:04:09 *
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)(CID=(PROGRAM=C:\ORANT\BIN\PLUS80W.EXE)(HOST=client_name)(USER=client_username)))
* (ADDRESS=(PROTOCOL=tcp)(HOST=REMTE_IP)(PORT=56366)) * establish * XE * 0
my /etc/hosts looks like:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain
localhost6 localhost6.localdomain6
192.168.100.70 servername.domain.com servername
I have NAT and open port 1521
in /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
Btw I can connect to oracle local:
-bash-4.1$ sqlplus system#XE
SQL*Plus: Release 11.2.0.2.0 Production on Fri Mar 21 14:19:07 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 -
64bit Production
SQL>
I also try to run sqlplus as administrator. No luck. Any idea?
UPDATE CLIENT SITE:
C:\Users\ClientUsername>tnsping80 venera
TNS Ping Utility for 32-bit Windows: Version 8.0.6.3.0 - Production on 21-MAR-20
14 14:27:17
(c) Copyright 1997 Oracle Corporation. All rights reserved.
Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HOST=servername.domain.com)(PORT=152
1))
OK (80 msec)
There is no support for Oracle Client 8 connecting to Oracle Database 11g
You need to upgrade your client.
I installed Oracle 11.2 on a Win7x64 laptop and almost everything works fine. One thing I don't understand, however. I can connect to the sample HR schema with:
sqlplus hr/password
but not with:
sqlplus hr/password#orcl
I get an ORA-12154: TNS:could not resolve the connect identifier specified.
I found this out by accident, as I was expecting the second option to be correct. Why can I leave out the TNS alias? I'm an Oracle beginner but when I connect to other environments, the TNS alias is required or I can't make a connection.
I have the following in my tnsnames.ora:
LISTENER_ORCL = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA = (DESCRIPTION =
(ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)))
(CONNECT_DATA = (SID = CLRExtProc)(PRESENTATION = RO)))
ORCL, DUMMY = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = orcl)))
I know for sure it's being used because both tnsping orcl and tnsping dummy are ok. Can someone explain this to me?
UPDATE 1: The output of lsnrctl status is the following:
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 11.2.0.1.0 - Production
Start Date 11-NOV-2012 00:43:22
Uptime 0 days 0 hr. 15 min. 53 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\app\Ronald\product\11.2.0\dbhome_1\network\admin\listener.ora
Listener Log File c:\app\ronald\diag\tnslsnr\Ronald-PDC\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
The result of SELECT name FROM v$database is one database: ORCL.
UPDATE 2: Output of tnsping orcl (formatted for readability).
Used parameter files:
C:\app\Ronald\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
OK (20 msec)
Did you actually create a database instance named ORCL?
Check out the actual name of your database with the command
lsnrctl status
This should tell you what services the listener knows about, which is what you're talking to when connecting with the # syntax. The reason you can connect without the #ORCL is that in that case you're using interprocess communication (IPC) and bypassing the listener, because the database is on the same computer as your SQL*Plus client session.
You can also find out the database name when you connect in the first example with this:
SELECT name FROM v$database;
EDIT:
Try the EZConnect syntax and see if that works:
sqlplus user/pw#localhost/ORCL
Keep in mind that TNSPING doesn't do anything besides contact the listener - it doesn't verify the database can be accessed.
One more thing: It looks like maybe TCP isn't a configured protocol for the listener? check your listener.ora file (in the same directory as your tnsnames.ora file). The entry for LISTENER should look something like this:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
My TNSPING output looks a bit different in one line near the start of output:
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521)))