cx_Oracle & Connecting to Oracle DB Remotely

后端 未结 6 1918
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 04:59

How do you connect to a remote server via IP address in the manner that TOAD, SqlDeveloper, are able to connect to databases with just the ip address, username, SID and pass

6条回答
  •  有刺的猬
    2020-11-28 05:14

    I like to do it this way:

    ip = '192.168.0.1'
    port = 1521
    SID = 'YOURSIDHERE'
    dsn_tns = cx_Oracle.makedsn(ip, port, SID)
    
    db = cx_Oracle.connect('username', 'password', dsn_tns)
    

    One of the main reasons I like this method is that I usually have a TNSNAMES.ORA file lying around someplace, and I can check that the dsn_tns object will do the right thing by doing:

    print dsn_tns
    

    and comparing the output to my TNSNAMES.ORA

提交回复
热议问题