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

后端 未结 7 808
你的背包
你的背包 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 10:07

    For those looking for how to specify service_name instead of SID.

    From changelog for SQLAlchemy 1.0.0b1 (released on March 13, 2015):

    [oracle] [feature] Added support for cx_oracle connections to a specific service name, as opposed to a tns name, by passing ?service_name= to the URL. Pull request courtesy Sławomir Ehlert.

    The change introduces new, Oracle dialect specific option service_name which can be used to build connect string like this:

    from sqlalchemy import create_engine
    from sqlalchemy.engine import url
    
    connect_url = url.URL(
        'oracle+cx_oracle',
        username='some_username',
        password='some_password',
        host='some_host',
        port='some_port',
        query=dict(service_name='some_oracle_service_name'))
    
    engine = create_engine(connect_url)
    

提交回复
热议问题