I have a connection string that looks like this
con_str = \"myuser/mypass@oracle.sub.example.com:1521/ora1\"
Where ora1
is the
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@'