Skip to content Skip to sidebar Skip to footer

How To Connect To An Oracle Database Using Cx_oracle With Service Name And Login?

I have a login, port number, host name and service name. How would I go about using the cx_Oracle.connect()?

Solution 1:

Something like this?

import cx_Oracle
con = cx_Oracle.connect('username/password@host_name/service_name')
print con.version
con.close()

Solution 2:

this works for me, you usually do need a port number

import cx_Oracle as orc 
user= 'username'
pwd = 'password'
host = 'url.or.path.to.db'#could look like path or url depending on where it's hosted
service_name = 'servicename'
portno = 1234#note this is dummy port no

con = orc.connect(user, pwd, '{}:{}/{}'.format(host,portno,service_name))

Solution 3:

In my case I used :

con = cx_Oracle.connect('username/password@'service_name')

No need to used host name oracle can implicitly connect the host name you just give the service name what ever it is.

Post a Comment for "How To Connect To An Oracle Database Using Cx_oracle With Service Name And Login?"