import cx_Oracle
print('connection start')
db_connection = cx_Oracle.connect("jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = <Host1>)(PORT = <port_number>)) (ADDRESS = (PROTOCOL = TCP)(HOST = <Host2>)(PORT = <port_number>)) (FAILOVER=true)(LOAD_BALANCE=true) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = <service_name>) (FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))", "<username>", "<password>")
print(db_connection)
print('connection successful')
我正在尝试使用 python 3.6.1 (Anaconda 4.4 dist) 连接到 oracle 11g 数据库,但遇到以下错误。
DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified
通过使用 Oracle-SQL-Developer 版本 17(使用相同的连接字符串),我能够成功连接到相同的 oracle 11g 数据库。
所以,我想知道我的代码是否有任何问题,或者 cx_Oracle 是否需要支持驱动程序等。任何帮助将不胜感激。