当前位置:Gxlcms > 数据库问题 > Python连接oracle

Python连接oracle

时间:2021-07-01 10:21:17 帮助过:18人阅读

cx_Oracle conn = cx_Oracle.connect(用户名/密码@IP/ServiceName) #1个参数 conn = cx_Oracle.connect(用户名, 密码, IP/ServiceName) #3个参数

打开 D:\app\username\product\11.2.0\client_1\NETWORK\ADMIN路径下的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:\app\username\product\11.2.0\client_1

尝试连接时,会报错如下:

cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "d:\app\sabre\product\11.2.0\client_1\bin\oci.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中,再次尝试连接,就可以了。

 

Python连接oracle

标签:github   ntc   tps   add   load   打开   https   protoc   esc   

人气教程排行