HiveBrain v1.2.0
Get Started
← Back to all entries
patternCritical

Connect with sqlplus from the command line using a connection string

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
fromtheconnectlinewithusingcommandsqlplusstringconnection

Problem

Let's say I have an Oracle database. I have a username = x, password = y, database = z, port = a, SID = b, and Hostname = c.

So, how do I connect correctly? I used many options like:

sqlplus x/y@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=c)(PORT=a))(CONNECT_DATA=(SID=z)(SERVER=DEDICATED)))'

sqlplus (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=c)(PORT=a))(CONNECT_DATA=(SID=b)))


But they usually give me the following errors:

ORA-12560: TNS:protocol adapter error

ORA-12514: TNS:listener does not currently know of service

Solution

Did you try:

sqlplus username/password@host:port/service
sqlplus x/y@c:a/b


Modern versions of sqlplus (11 and higher) understand this syntax and you don't need a tnsnames.ora file.

Code Snippets

sqlplus username/password@host:port/service
sqlplus x/y@c:a/b

Context

StackExchange Database Administrators Q#65032, answer score: 113

Revisions (0)

No revisions yet.