title: How do I fix OCIServerAttach failing with DATABASE error: ORA-12541: TNS:no listener?
body: <p>I have my client on a Windows machine and the Oracle server on a Centos Virtual machine.</p>
  
  <p>I am able to connect from my PC to the server using SQLPlus using the following string:</p>
  
  <pre><code>sqlplus MyName/MyPassword@IPADDRESS/xe
  </code></pre>
  
  <p>My tnsnames.ora files is:</p>
  
  <pre><code># tnsnames.ora Network Configuration File:
  
  XE =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = IPAddress)(PORT = 1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = XE)
      )
    )
  
  EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      )
      (CONNECT_DATA =
        (SID = PLSExtProc)
        (PRESENTATION = RO)
      )
    )
  </code></pre>
  
  <p>However, when I try to use the same connection information from my application the connections fails in the OCIServerAttach call.</p>
  
  <p>Here is the code framework:</p>
  
  <pre><code>OCIEnvCreate(&amp;tmpEnv,
                  OCI_OBJECT | OCI_THREADED,
                  NULL,
                  NULL,
                  NULL,
                  NULL,
                  0,
                  NULL);
  
  OCISessionBegin(serviceContextHandle_, errorHandle_, sessionHandle_, OCI_CRED_RDBMS, OCI_DEFAULT);
  
  
  OCIHandleAlloc( (dvoid *) environmentHandle_, (dvoid **) &amp;serviceContextHandle_, OCI_HTYPE_SVCCTX, (size_t) 0, (dvoid **) 0);
  OCIHandleAlloc( (dvoid *) environmentHandle_, (dvoid **) &amp;serverHandle_, OCI_HTYPE_SERVER, (size_t) 0, (dvoid **) 0);
  OCIHandleAlloc( (dvoid *) environmentHandle_, (dvoid **) &amp;errorHandle_, OCI_HTYPE_ERROR, (size_t) 0, (dvoid **) 0);
  OCIHandleAlloc( (dvoid *) environmentHandle_, (dvoid **) &amp;sessionHandle_, OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0);
  
   /* here path is an std::string which contains the IPAddress followed by '/xe'*/
  
  result =  OCIServerAttach( serverHandle_, errorHandle_, (text *)path_.c_str(), (sb4)path_.length(), 0);
  </code></pre>
  
  <p>The IPAddress matches the IPAddress in the tnsnames.ora and listener.ora file.  There is no port number being used as I intended to use the default 1521.</p>
  
  <p>To the best of my knowledge the listeners are set up and working correctly otherwise I would not be able to connect via SQLPlus.  My ORACLE_HOME value is as I expect.  The install directory is in my PATH.</p>
  
  <p>Anyone have any ideas of what might be wrong?</p>