0

I need to check oracle connectivity using python script. My oracle connection string is in below format.

jdbc:oracle:thin:@ldap://ovd.mycomp.com:38901/cn=Oraclecontext,o=eus,dc=mycomp,dc=com/pidev ldap://ovd- mwdc.mycomp.com:38901/cn=Oraclecontext,o=eus,dc=mycomp,dc=com/pidev.

I tried https://dbajonblog.wordpress.com/2019/12/18/python-and-cx_oracle-for-oracle-database-connections/ but that did not help. Could you please help me. Thanks in advance.

Sunil Chauraha
  • 525
  • 1
  • 7
  • 21

2 Answers2

1

The general cx_Oracle documentation on working with JDBC and Oracle SQL Developer Connection Strings has some info however if you're using LDAP you'll need to do some extra configuration. See https://stackoverflow.com/a/32151099/4799035 and https://github.com/oracle/node-oracledb/issues/1212#issuecomment-591940440 The steps are the same for cx_Oracle. Also see Connect to DB using LDAP with python cx_Oracle

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
0

I created following script using cx_oracle, which works fine. only restriction is the dns name should be TNS entry.

Script:

import cx_Oracle
import sys
from botocore.exceptions import ClientError
connection = None
def isOracleHealthy(dbname, username, password, dns, log):
    try:
        sys.stderr.write(dns)
        connection=cx_Oracle.connect("{}/{}@{}".format(username, password, dns))
        cur=connection.cursor()
        for result in cur.execute("SELECT * FROM dual"):
            log.info(result)
        return True
    except Exception as e:
        sys.stderr.write(dbname+' Oracle health check failed.\n')
        log.error(dbname+' Oracle health check failed.')    
        return False
Sunil Chauraha
  • 525
  • 1
  • 7
  • 21