【问题标题】:Python to connect to Oracle with OVDPython 使用 OVD 连接到 Oracle
【发布时间】:2021-02-10 17:00:21
【问题描述】:

我需要使用 python 脚本检查 oracle 连接。 我的 oracle 连接字符串格式如下。

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。

我试过https://dbajonblog.wordpress.com/2019/12/18/python-and-cx_oracle-for-oracle-database-connections/,但没有帮助。 请你帮助我好吗。 提前致谢。

【问题讨论】:

  • 你得到的错误是.....什么?

标签: python oracle


【解决方案1】:

关于使用JDBC and Oracle SQL Developer Connection Strings 的一般 cx_Oracle 文档有一些信息,但是如果您使用的是 LDAP,则需要进行一些额外的配置。请参阅 https://stackoverflow.com/a/32151099/4799035https://github.com/oracle/node-oracledb/issues/1212#issuecomment-591940440 步骤与 cx_Oracle 相同。另见Connect to DB using LDAP with python cx_Oracle

【讨论】:

    【解决方案2】:

    我使用 cx_oracle 创建了以下脚本,效果很好。 唯一的限制是 dns 名称应该是 TNS 条目。

    脚本:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-06
      • 2020-02-06
      • 1970-01-01
      • 2018-12-13
      • 2019-12-26
      • 2016-07-27
      • 2012-07-16
      • 2021-08-01
      相关资源
      最近更新 更多