title: ORA-12514: TNS:listener does not know of service (The service is running and listed by lsnrctl)
body: <p>I'm trying to access an Oracle database using ODBC in PHP. (Apache 2, PHP 5, ODBC driver and Oracle database 11.2 are installed on Ubuntu Server 14.04 in VirtualBox.)</p>
  
  <p>I've managed to install Oracle database and I think I've configured tnsnames.ora and ODBC driver:</p>
  
  <ul>
  <li>I'm able to login using sqlplus and execute SQL;</li>
  <li>tnsping works;</li>
  <li>I actually installed 12.1 version of ODBC driver when database version is 11.2, but I think it works fine.</li>
  </ul>
  
  <p>But when I call odbc_connect in PHP, I get the following error:</p>
  
  <blockquote>
    <p>Warning: odbc_connect(): SQL error: [unixODBC][Oracle][ODBC][Ora]ORA-12514: TNS:listener does not currently know of service requested in connect descriptor , SQL state S1000 in SQLConnect in /var/www/html/index.php on line 61</p>
  </blockquote>
  
  <p>I believe driver works fine because it's mentioned in that error. When I tried calling <code>odbc_connect</code> without driver installed, I had another error.</p>
  
  <p>If I specify <code>@DB</code> when using sqlplus, I get some strange errors (listings down there).</p>
  
  <hr>
  
  <h2>Configuration</h2>
  
  <p>This is how tnsnames.ora configured:</p>
  
  <pre><code># tnsnames.ora Network Configuration File:
  
  MYNAME =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = database)(PORT = 1521))
      )
      (CONNECT_DATA = (SID = XE))
    )
  
  DB =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = database)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = ORCL)
      )
    )
  
  EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      )
      (CONNECT_DATA =
        (SID = PLSExtProc)
        (PRESENTATION = RO)
      )
    )
  </code></pre>
  
  <p><code>DB</code> and <code>EXTPROC_CONNECTION_DATA</code> sections were here when I started, but I also added <code>MYNAME</code> to test whether I should use <code>(CONNECT_DATA = (SID = XE))</code> instead of <code>(SERVICE_NAME = ORCL)</code>.</p>
  
  <hr>
  
  <h2>sqlplus connect errors</h2>
  
  <p>I'm unable to login like <code>sqlplus dbuser@DB</code>:</p>
  
  <pre><code>sqlplus dbuser@DB
  
  SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
  
  Copyright (c) 1982, 2011, Oracle. All rights reserved.
  
  Enter password:
  ERROR:
  ORA-12641: Authentication service failed to initialize
  </code></pre>
  
  <p>If I change <code>SQLNET.AUTHENTICATION_SERVICES</code> from <code>ALL</code> to <code>NONE</code>, I'm unable to login using sqlplus at all:</p>
  
  <pre><code>sqlplus dbuser@DB
  
  SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
  
  Copyright (c) 1982, 2011, Oracle. All rights reserved.
  
  Enter password:
  ERROR:
  ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
  </code></pre>
  
  <hr>
  
  <pre><code>sqlplus dbuser
  
  SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
  
  Copyright (c) 1982, 2011, Oracle. All rights reserved.
  
  Enter password:
  ERROR:
  ORA-01034: ORACLE not available
  ORA-27101: shared memory realm does not exist
  Linux-x86_64 Error: 2: No such file or directory
  Process ID: 0
  Session ID: 0 Serial number: 0
  </code></pre>
  
  <hr>
  
  <h2>Relevant SO questions</h2>
  
  <p><a href="https://stackoverflow.com/questions/12532939/ora-12514-errortns-listener-error">ORA 12514 error:TNS listener error</a></p>
  
  <blockquote>
    <ol>
    <li>Check if a database instance is up and running</li>
    <li>Check the output of the <code>lsnrctl service</code> command and see what services are registered.</li>
    <li>Check if you have <code>SERVICE_NAME</code> correctly specified when connecting to the instance.</li>
    <li>If it happens that database instance stared before listener did, sometimes you just need to wait a little or you can execute <code>alter system register</code> in order to register the instance.</li>
    </ol>
  </blockquote>
  
  <ol>
  <li>Up and running;</li>
  <li>My service seems is listed;</li>
  <li>Specified correctly;</li>
  <li>Doesn't help.</li>
  </ol>
  
  <p><a href="https://stackoverflow.com/questions/33046649/ora-12514-tnslistener-does-not-currently-know-of-service-requested-in-connect-d">ORA-12514 TNS:listener does not currently know of service requested in connect descriptor for existing service</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21553557/ora-12514-tnslistener-does-not-currently-know-of-service-requested-in-connect">ORA-12514: TNS:listener does not currently know of service requested in connect descriptor</a></p>
  
  <p>Tried both (<code>local_listener</code> solution).</p>
  
  <hr>
  
  <h2>The Question</h2>
  
  <p>So I'm missing something in tnsnames.ora? Or there is some other problem I'm encountering?</p>
  
  <hr>
  
  <h2>Update 1</h2>
  
  <p><code>lsnrctl status</code>:</p>
  
  <pre><code>LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 18-FEB-2016 20:27:56
  
  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                18-FEB-2016 20:21:31
  Uptime                    0 days 0 hr. 6 min. 25 sec
  Trace Level               off
  Security                  ON: Local OS Authentication
  SNMP                      OFF
  Default Service           ORCL
  Listener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
  Listener Log File         /u01/app/oracle/diag/tnslsnr/database/listener/alert/log.xml
  Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=database)(PORT=1521)))
  Services Summary...
  Service "ORCL" has 1 instance(s).
    Instance "XE", status READY, has 1 handler(s) for this service...
  Service "ORCLXDB" has 1 instance(s).
    Instance "XE", status READY, has 1 handler(s) for this service...
  Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
  The command completed successfully
  </code></pre>
  
  <p><code>sqlplus dbuser</code> (when <code>SQLNET.AUTHENTICATION_SERVICES</code> is set to <code>ALL</code>):</p>
  
  <pre><code>SQL*Plus: Release 11.2.0.2.0 Production on Thu Feb 18 20:26:50 2016
  
  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&gt;
  </code></pre>