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

后端 未结 7 809
你的背包
你的背包 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:55

    I thought during a while that I would not be able to use Magic SQL (%sql, %%sql) because of service name issue in connection that would force to use the alternative way described above with cx_Oracle.connect(), cx_Oracle.makedsn()... I finally found a solution working for me: declare and set a variable for the service name first and then use it in the command (since not working if literal string for service name put in the command !)

    import cx_Oracle
    
    user='youruser'
    pwd='youruserpwd'
    dbhost='xx.xx.xx.xx'
    service='yourservice'
    
    %load_ext sql
    %sql oracle+cx_oracle://$user:$pwd@$dbhost:1521/?service_name=$service
    

    output (what you get in successful connection):

    u'Connected: youruser@'
    

提交回复
热议问题