python - cx_Oracle doesn't connect when using SID instead of service name on connection string -
i have connection string looks this
con_str = "myuser/mypass@oracle.sub.example.com:1521/ora1"
where ora1
sid of database. using information in sql developer works fine, meaning can connect , query without problems.
however, if attempt connect oracle using string, fails.
cx_oracle.connect(con_str) databaseerror: ora-12514: tns:listener not know of service requested in connect descriptor
this connection string format works if ora1
service name, though.
i have seen other questions seem have reverse of problem (it works sid, not service name)
- using oracle service names sqlalachemy
- oracle sid , service name; connection problems
- cx_oracle & connecting oracle db remotely
what proper way connect oracle, using cx_oracle
, using sid
, not service name? how do without need adjust tnsnames.ora
file? application distributed many users internally , making changes tnsnames
file less ideal when dealing users without administrator privileges on windows machines. additionally, when use service name, don't need touch file @ , keep way.
i similar scenario, able connect database using cx_oracle.makedsn()
create dsn string given sid
(instead of service name):
dsnstr = cx_oracle.makedsn("oracle.sub.example.com", "1521", "ora1")
this returns
(description=(address_list=(address=(protocol=tcp)(host=oracle.sub.example.com)(port=1521)))(connect_data=(sid=ora1)))
which can used cx_oracle.connect()
connect database:
con = cx_oracle.connect(user="myuser", password="mypass", dsn=dsnstr) print con.version con.close()
Comments
Post a Comment