我使用Toad连接到我的Oracle数据库,它工作得很好,但是我尝试使用cx_Oracle连接到同一个数据库,我的程序被.connect()方法卡住了。
我认为问题出在host名称上,但我不能确定,因为没有错误存在,只是没有通过connect()调用。
import cx_Oracle
CONN_INFO = {'host': '\\\\SERVERNAMEUSEDINTOAD\\',
'port': 1111,
'user': 'USER123',
'psw': 'password',
'service': 'dbname.somesite.com'}
print("test1")
CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO)
print("test2")
con = cx_Oracle.connect(CONN_STR)
print("test3")
print(con.fetchmany([1]))控制台:
test1
test2我到了test2,但没有到test3。我是否正确使用了主机名?主机是网络上的内部服务器。
TOAD应用程序只显示SERVERNAMEUSEDINTOAD,所以我也尝试了:
'host': 'SERVERNAMEUSEDINTOAD'但这导致了以下错误:
test1
test2
Traceback (most recent call last):
File "C:/Users/name/PycharmProjects/WorkFlow/test.py", line 12, in <module>
con = cx_Oracle.connect(CONN_STR)
cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified发布于 2019-02-02 05:50:36
我必须做两件事才能让你的例子在我的笔记本电脑上工作。
我必须更新我的sqlnet.ora才能拥有这一行:
names.directory_path = (TNSNAMES,EZCONNECT)
而不是
names.directory_path = (TNSNAMES)
然后我不得不使用我的主机的ip地址而不是主机名。
我不认为这是cx_oracle中的一个错误,因为sqlplus也不能使用相同的语法。但是,它与我的sqlnet.ora中的ip地址和EZCONNECT一起工作。
鲍比
https://stackoverflow.com/questions/54487013
复制相似问题