cx_Oracle doesn't connect when using SID instead of service name on connection string

后端 未结 7 833
你的背包
你的背包 2020-12-13 09:14

I have a connection string that looks like this

con_str = \"myuser/mypass@oracle.sub.example.com:1521/ora1\"

Where ora1 is the

7条回答
  •  星月不相逢
    2020-12-13 09:56

    I a similar scenario, I was able to connect to the database by using cx_Oracle.makedsn() to create a dsn string with a given SID (instead of the service name):

    dsnStr = cx_Oracle.makedsn("oracle.sub.example.com", "1521", "ora1")
    

    This returns something like

    (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle.sub.example.com)(PORT=1521)))(CONNECT_DATA=(SID=ora1)))
    

    which can then be used with cx_Oracle.connect() to connect to the database:

    con = cx_Oracle.connect(user="myuser", password="mypass", dsn=dsnStr)
    print con.version
    con.close()
    

提交回复
热议问题