我使用 cx_Oracle 模块连接到独立的 Oracle 服务器,如下所示
import cx_Oracle
CONN_INFO = {
'host': 'xxx.xx.xxx.x',
'port': 12345,
'user': 'user_name',
'psw': 'your_password',
'service': 'abc.xyz.com',
}
CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO)
connection = cx_Oracle.connect(CONN_STR)
但是由于扫描IP没有机器和自己的用户名密码,我们如何连接?
最佳答案
Es documentation 中描述,您可以简单地使用tnsnames.ora
中定义的名称。
假设您的 RAC
tnsnames 条目名为 MAXIMIR
,您可以使用它进行连接
con = cx_Oracle.connect("my_usr", "my_pwd", "MAXIMIR", encoding="UTF-8")
或者,您可以在 dns
变量中传递整个连接字符串
dsn = """(DESCRIPTION=
(FAILOVER=on)
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=scan1)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=scan2)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=MAXIMIR)))"""
connection = cx_Oracle.connect("my_usr", "my_pwd", dsn, encoding="UTF-8")
关于python - 如何在python中使用SCAN连接到Oracle-RAC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59368839/