Wednesday, June 9, 2010

How to connect to a Db via sqlplus without editing tnsnames.ora?

I've not been given admin privilege to edit the tnsnames.ora file in my pc.I had been facing difficulties to connect to other dbs which are not in my tnsnames.ora file. So two methods given to overcome this >10g .(Toad has implemented this feature)
(1). Use,
sqlplus user_name/password@//host/service_name
Eg: > sqlplus scott/tiger@//192.168.161.66/orcl
you may get "ORA-12154: TNS:could not resolve the connect identifier specified"
Check u have added/uncommented following line in sqlnet.ora which is at \11.1.0\client_1\network\admin
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
(2). Use, Here it's not necessary to have above entry in sqlnet.ora file.
sqlplus scott/tigger@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.161.66)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(service_name=orcl)))'
Note: No line breaks, No spaces and No semicolon(;) at the end
Reference : Oracle Magazine July/August 2010