oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
889 stars 361 forks source link

Connecting to Oracle Wallet using cx_Oracle #653

Closed priyuganesan closed 1 year ago

priyuganesan commented 1 year ago
  1. What versions are you using?
platform.platform: Windows-10-10.0.19045-SP0 sys.maxsize > 2**32: True platform.python_version: 3.9.13 cx_Oracle.version: 8.3.0 cx_Oracle.clientversion: (12, 2, 0, 1, 0) 2. Describe the problem

DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified |   Can someone please help me understand what I could be missing here ?

  1. Include a runnable Python script that shows the problem.
cjbj commented 1 year ago
priyuganesan commented 1 year ago

Did you set TNS_ADMIN?

Review https://cx-oracle.readthedocs.io/en/latest/user_guide/connection_handling.html#connecting-to-oracle-cloud-autonomous-databases

(PS, upgrade from cx_Oracle to python-oracledb)

Yes, I set that to the folder that has the tnsnames.ora and sqlnet.ora. (yes, will look to upgrade to python-oracledb soon)

cjbj commented 1 year ago

Can SQL*Plus connect?

If so, share more details about the exact cx_Oracle code and network file configuration so we can check you have correct values and environment.

priyuganesan commented 1 year ago

Can SQL*Plus connect?

If so, share more details about the exact cx_Oracle code and network file configuration so we can check you have correct values and environment.

I tried SQLPlus and see the same error there too

Z:>sqlplus /@walletalias

SQL*Plus: Release 19.0.0.0.0 - Production on Wed May 17 09:48:49 2023 Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle. All rights reserved.

ERROR: ORA-12154: TNS:could not resolve the connect identifier specified

My tnsora looks like this image

My sqlnet image

My python code that tries to establish connection with the db self.connector = cx_Oracle.Connection(dsn="mynetalias")

Please let me know if I am missing anything else here....

anthony-tuininga commented 1 year ago

Have you set the environment variable TNS_ADMIN to point to the location of your sqlnet.ora and tnsnames.ora files? The error you are getting suggests that it can't find your tnsnames.ora or the alias found within it!

priyuganesan commented 1 year ago

Have you set the environment variable TNS_ADMIN to point to the location of your sqlnet.ora and tnsnames.ora files? The error you are getting suggests that it can't find your tnsnames.ora or the alias found within it!

I think I do...here's where my .ora files are image

Here's my env variable image

anthony-tuininga commented 1 year ago

That value needs to be set in the shell prior to running SQL*Plus. Is it? Is the name you are trying to access actually found in the tnsnames.ora file? The error suggests that one of the two is not true. You will need to debug your configuration. You can also try with python-oracledb thin mode as you might get different error messages that may be helpful in diagnosing your configuration problems. Note that thin mode doesn't support "auto-login" wallets which you are trying to use here -- but you can certainly attempt to connect using a dummy user name and password. If you get ORA-01017 then you know the connection was successful but the authorization was not. At that point thick mode should also work. As a potential help:

# thick mode
import oracledb
oracledb.init_oracle_client(config_dir=the_location_of_tnsnames)
conn = oracledb.connect(dsn="mynetalias")
# thin mode
import oracledb
conn = oracledb.connect(dsn="mynetalias", config_dir=the_location_of_tnsnames, user="dummy", password="dummy")

You can also just do this as a way of checking the basic configuration:

import oracledb
params = oracledb.ConnectParams(config_dir=the_location_of_tnsnames)
params.parse_connect_string("mynetalias")
stale[bot] commented 1 year ago

This issue has been automatically marked as inactive because it has not been updated recently. It will be closed if no further activity occurs. Thank you for your contributions.