cx_Oracle连接问题

时间:2016-01-22 05:51:21

标签: python oracle cx-oracle

我已经意识到这个oracle DB,尝试了几种命令组合,但仍然无法连接。  以下是我最近的连接尝试。

ip = "173.37.65.217" #datamart
port = '1810'
SID = 'fntr3prd.cisco.com'  #'ARCHIVE_HC6_ARCH'#"fntr3prd"
username = 'xx' # I don’t have permission to share
password = 'xx' # I don’t have permission to share
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
con = cx_Oracle.connect(username,password,dsn_tns)
cur = con.cursor()

cur.execute("select * from  ARCHIVE_HC6_ARCH”)

我得到的例外......

  

Traceback(最近一次调用最后一次):文件   " /Users/tlombard/Desktop/FY16Metrics/ppmArchive.py" ;,第12行,在          con = cx_Oracle.connect(username,password,dsn_tns)DatabaseError:ORA-12505:TNS:侦听器当前不知道SID   在连接描述符中给出

注意:如下所示,我可以使用sqlplus ...

连接到此数据库
  

SQL> DESC ARCHIVE_HC6_ARCH名称是否为空?类型   ----------------------------------------- -------- - --------------------------- ARCH_FISCAL_DT NOT NULL DATE HC NUMBER DE_DT_YN VARCHAR2(30)   RESOURCE_POSITION VARCHAR2(150)CLIENT_FUNDED
  VARCHAR2(200)RESOURCE_NAME VARCHAR2(300)   RESOURCE_DEPT_NAME VARCHAR2(150)RESOURCE_DEPT_NO
  NUMBER RESOURCE_ID VARCHAR2(50)RESOURCE_MANAGER
  VARCHAR2(200)RESOURCE_POOL VARCHAR2(255)RESOURCE_ROLE
  VARCHAR2(255)RESOURCE_TITLE VARCHAR2(500)   RESOURCE_TYPE VARCHAR2(7)ROLE_CATEGORY VARCHAR2(255)   ROLE_GROUP VARCHAR2(255)L0 VARCHAR2(20)L1
  VARCHAR2(20)L2 VARCHAR2(20)L3 VARCHAR2(20)   L4 VARCHAR2(20)UNNAMED VARCHAR2(30)   WORK_COUNTRY VARCHAR2(100)WORK_SITE VARCHAR2(300)   MONTH_KEY NUMBER MONTH VARCHAR2(50)   QUARTER_KEY NUMBER QUARTER_NAME VARCHAR2(50)   YEAR_NAME VARCHAR2(50)BPF VARCHAR2(255)   PROJECT_PRIORITY VARCHAR2(100)PROJECT_STATUS
  VARCHAR2(200)PRODUCT_FAMILY VARCHAR2(200)PIN_AGGREGATED                     VARCHAR2(1000)PROJECT_OS VARCHAR2(2000)PLATFORM VARCHAR2(765)PROJECT_CLASS VARCHAR2(100)   PROJECT_ID VARCHAR2(300)PROJECT_INITIATIVE
  VARCHAR2(150)PROJECT_LEAD VARCHAR2(150)PROJECT_MGR
  VARCHAR2(150)PROJECT_CATEGORY VARCHAR2(300)   PROJECT_NAME VARCHAR2(1500)PROJECT_HEALTH
  VARCHAR2(100)PLANNED_RELEASE VARCHAR2(500)   PROJECT_TECH_AREA VARCHAR2(150)PROJECT_TYPE
  VARCHAR2(150)WORK_COUNTRY_SORT VARCHAR2(15)   PROGRAM_NAME VARCHAR2(500)YEAR_KEY NUMBER   ARCH_FISCAL_MONTH VARCHAR2(100)解决方案VARCHAR2(500)   PROJECT_ROLE_CATEGORY VARCHAR2(255)RESORUCE_DEPT_FUNCTION
  VARCHAR2(500)RESOURCE_MANAGER_ID VARCHAR2(255)   RESOURCE_ACTIVE VARCHAR2(50)PROJECT_ACTIVE
  VARCHAR2(100)PROJECT_ORG VARCHAR2(255)L5
  VARCHAR2(20)QUADRANT VARCHAR2(255)

     

SQL>

关于我接下来应该尝试什么的任何想法?

3 个答案:

答案 0 :(得分:2)

可能是您使用服务名称而不是sid

尝试

dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)

http://cx-oracle.readthedocs.org/en/latest/module.html?highlight=makedsn#cx_Oracle.makedsn

答案 1 :(得分:0)

假设您对数据库有其他类型的访问权限,请尝试

SELECT sys_context('USERENV', 'SID') FROM DUAL;

并使用它代替

SID = 'fntr3prd.cisco.com'

答案 2 :(得分:0)

您是否已安装oracle客户端并为其完成LDAP配置?