import cx_Oracle conn = cx_Oracle.connect('用户名/密码@IP/ServiceName') #1个参数 conn = cx_Oracle.connect('用户名', '密码', 'IP/ServiceName') #3个参数
打开 D:appusernameproduct11.2.0client_1NETWORKADMIN路径下的tnsnames.ora
此处的IP为下列连接描述的HOST,ServiceName为SERVICE_NAME
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 111.111.111.111)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
刚刚开始连接时,我机器上的oracle是32位客户端连64位服务器端,客户端位于 D:appusernameproduct11.2.0client_1
尝试连接时,会报错如下:
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "d:appsabreproduct11.2.0client_1inoci.dll is not the correct architecture". See https://oracle.github.io/odpi/doc/installation.html#windows for help
按照提示中的链接,找到oracle的64位客户端文件package,下载,放到D:instantclient_11_2,然后把这个路径添加到系统path中,再次尝试连接,就可以了。