问题
I have a set of python scripts that use cx_Oracle to connect to a remote DB. This is a large project, were this connections are used several times. Additionally, I produce an .exe file that is distributed and should be as self-contained as possible. In other words, if I send you the .exe, you should be able to run it without any extra tinkering (I use pyinstaller )
Right now, I get a connection using
ip = 'myhost.example.pt'
port = 1521
SID = 'MYDB_PRD.EXAMPLE.PT'
dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)
con = cx_Oracle.connect(username_bd, password_bd, dsn_tns, encoding='UTF-8')
The object con
is used thorough the script, always as the connection argument for a pandas read_sql
function call.
Everything is ok, except that my DB Admins are asking to setup this connection using ldap. I've search around, and the only solution I find to do it involves creating a file somewhere on the client... Is there no other way? Can't I pass the ldap configurations directly on the script?
回答1:
Properly configured SQLNet.ORA and LDAP.ORA files are required on the client to use LDAP as a TNSNAMES repository. You can create both SQLNet.ORA and LDAP.ORA in your script and load these configuration files using cx_oracle.init_oracle_client(lib_dir="..path to configuration files..").
来源:https://stackoverflow.com/questions/64426038/connect-to-db-using-ldap-with-python-cx-oracle