joaovzg
joaovzg

Reputation: 50

How to solve ORA-12154: TNS error when using PHP OCI8 oci_connect in Azure

I'm trying to connect to the oracle database of a new partner, 11g Release 11.2.0.4.0, and I'm receiving the following error:

Warning: oci_connect(): ORA-12545: Connect failed because target host or object does not exist

The partner affirms that the connection string provided is correct.

This is the current structure of mine oci_connect() and the said connection string being used:

$connection_string = '(DESCRIPTION = (ADDRESS_LIST = (LOAD_BALANCE = ON)(FAILOVER = ON)(ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = SERVICE_NAME)))'
$conn = oci_connect($username, $password, $connection_string, 'UTF8', OCI_DEFAULT);

But, when using the following structure:

$connection_string = 'user/password@host:port/service_name'
$conn = oci_connect($username, $password, $connection_string, 'UTF8', OCI_DEFAULT);

It returns:

Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified

To give a clear picture of what I did, below are the steps I took to create my App-Service and install the oci8 php driver:

  1. I created an Azure App-Service, that uses PHP, Version 7.3.26;
  2. Created a new oracle directory inside /home/site;
  3. Added the instant client to the new oracle directory, in this case it was the Instant Client Linux x86-64 18.5.0.0.0v (bouth the basic and the sdk packages);
  4. Proceded to use the command pecl install oci8-2.2.0;
  5. I pointed out the location of the instant client during the installation process, the oci8 driver was installed successfully;
  6. Copied the new oci8.so file to an ext directory inside /home/site;
  7. Created a php.ini file, with extension=/home/site/ext/oci8.so set in;
  8. Defined the PHP_INI_SCAN_DIR config as being /usr/local/etc/php/conf.d:/home/site/ini;
  9. Defined the LD_LIBRARY_PATH as being /home/site/oracle/instantclient_18_5.

After that I could confirm the existence of the oci8 extension on my phpinfo() page.

Those steps where made following this documentation: Azure App Service Linux - Adding PHP Extensions

I also have latter defined the ORACLE_HOME setting as being /home/site/oracle/instantclient_18_5, but it had no diferences.

I'm out of ideas, can someone please indicate me what could be causing this problem and how can I solve it.


EDIT:

After further conversations with the partner it becamed clear that there isn't no way for me to connect to their database considering the current configuration of the same. As noted int the comments by Christopher Jones, its a problem of networking, ORA-12545, ORA-12541, ORA-12514, & ORA-01017 – How to fix for SQL Developer, and, in this case, lack of proper feedback.

Upvotes: 1

Views: 1449

Answers (1)

TekOps
TekOps

Reputation: 196

Ok,

So I fought with this for a long time and could never get it to find the tnsnames.ora file no matter what I did. Finally I decided to pull the connection string definition out of the tnsnames.ora file and insert it directly into the oci_connect statement as the connection string and it worked:

//$connection_string = '(DESCRIPTION = (ADDRESS_LIST = (LOAD_BALANCE = ON)(FAILOVER = ON)(ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = SERVICE_NAME)))'
$connection_string = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.10)(PORT=1521))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = pdb_mypdb.xyz.com)))';
$conn = oci_connect("mypdb", "mypdbpw", $connection_string );

What is even more cool is that in a lot of third-party programs, when they ask for the name of the oracle server, you can put the ENTIRE tnsnames.ora CONNECT definition (like above, in $connection_string) in to the "server name" and it will work. You don't even need tnsnames.ora, etc. and all the load-balancing, etc., will all work.

Good luck, David

Upvotes: 0

Related Questions