oracle-databaseoracle11gdatabase-connectiontnsnamestns

ora-12504: tns:listener was not given the service_name in connect_data in windows 10


I'm connecting my application with Oracle database but it gives above error when I trying to login my application.

I'm already tried to different changes in tnsnames.ora file.

Following code is in my listener.ora file:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\app\DELL\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:C:\app\DELL\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = C:\app\DELL

And following code is in tnsnames.ora file:

XE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = xe) ) )

LISTENER_XE = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

ORACLE_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) (CONNECT_DATA = (SID = CLRExtProc) (PRESENTATION = RO) ) )


Solution

  • DATA SOURCE should be set to the TNS name, not localhost so:

    <add name="DSN" connectionString="DATA SOURCE=XE;USER ID=ocr_test;PASSWORD=pass;" providerName="Oracle.DataAccess.Client"/>
    

    FYI also, ConnectionStrings.com is a great reference.