2

I have been given these details regarding the database.

Userid & Password, 
LDAP Server : stpoid.corp.com:3060:3131, 
Context: cn=OracleContext,dc=corp,dc=com, 
DB server= PRD1. 

I can successfully connect and query the database using sql developer with these details. I'm running python3.6 with cx_oracle on windows 10.

I read about the instruction in https://stackoverflow.com/a/32151099/4799035 and vaguely figured out that I need to create sqlnet.ora and/or tnsnames.ora and/or ldap.ora file. But the instructions don't work well on windows.

But i'm not sure where in windows file structure should I create them? or can I create them anywhere and set them in path variables? what should be the name for the variable? and how should I configure the cx_oracle.connect() parameters? can I pass these parameters in the cx_oracle.makedns()?

Any document or guidance will be helpful.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
S4nd33p
  • 431
  • 2
  • 7
  • 17

1 Answers1

2

See the cx_Oracle manual entry Optional Oracle Net Configuration Files

If cx_Oracle is using Instant Client libraries, then you can put the files in a network\admin subdirectory, for example c:\instantclient_19_5\network\admin\tnsnames.ora. This is the default location for applications using the libraries from c:\instantclient_19_5.

Alternatively, if you put them in a custom directory, for example in c:\configfiles, then you can set the TNS_ADMIN environment variable to that directory. You could set this before Python is started, or (with cx_Oracle 6 or later) you can set it before in your apps:

import os
import cx_Oracle

# Do this before opening a connection
os.environ['TNS_ADMIN'] = 'c:\configfiles'
Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
  • Thanks Chris, I did follow through that and a bunch of other stuff. Now I'm able to get the connection working if my sqlnet.ora says >> NAMES.DIRECTORY_PATH = (LDAP, TNSNAMES) but I get >> "cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified" if I leave only >> NAMES.DIRECTORY_PATH = (LDAP) . That means to me that the connection is workin over the TNS but not working over LDAP. What could be causing this? I'm using the same LDAP for SQL developer and that's working.. Any ideas? – S4nd33p Dec 19 '19 at 06:36
  • Update your original post with all the relevant code (e.g. the connection call) and configuration detail. – Christopher Jones Dec 20 '19 at 01:54