cannot connect to oracle database with SQLPLUS via service name

3.1k Views Asked by At

I am trying to connect to an Oracle database from SQLPLUS using service_name but I received the

ORA-12154 error (ORA-12154: TNS:could not resolve the connect identifier specified.

NOTE: when I am using the SQL Developer, everything works fine.

here it is my tnsnames.ora settings:

SAMPLEDB =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sampledb)
    )
  )

This is the connection command I use:

sqlplus test/password@localhost:1521/sampledb

Can someone tell me what am I doing wrong, please?

1

There are 1 best solutions below

1
On

Besides the obvious (the command to start SQL*Plus is, of course, sqlplus), you are missing a line in the definition of the SAMPLEDB connect identifier.

Insert between the first and the second line the following line (EXACTLY as written below):

  (DESCRIPTION =

You must have deleted it somehow.

SAMPLEDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = sampledb)
    )
  )