Skip to content

Can't connect via wallet to two different databases at the same time #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thiagodma opened this issue Apr 27, 2021 · 4 comments
Closed
Labels

Comments

@thiagodma
Copy link

  1. What versions are you using?

Database Version: 18c
platform.platform: Linux-3.10.0-957.5.1.el7.x86_64-x86_64-with-centos-7.6.1810-Core
sys.maxsize > 2**32: True
platform.python_version: 3.6.9
cx_Oracle.version 8.1.0
cx_Oracle.clientversion (19, 6, 0, 0, 0)

  1. Is it an error or a hang or a crash? Error

  2. What error(s) or behavior you are seeing?

Traceback (most recent call last):
File "test.py", line 27, in
sis = Sisredex()
File "test.py", line 19, in init
cx_Oracle.init_oracle_client(config_dir="/opt/flx/config/sisredex")
cx_Oracle.ProgrammingError: Oracle Client library has already been initialized

  1. Include a runnable Python script that shows the problem.
import cx_Oracle

class Database1():
    def __init__(self):
        cx_Oracle.init_oracle_client(config_dir="/dir/to/sqlnet/tnsnames1")
    def get_conn():
        conn = cx_Oracle.connect(dsn="alias1")
        conn.ping()
        return conn

class Database2():
    def __init__(self):
        cx_Oracle.init_oracle_client(config_dir="/dir/to/sqlnet/tnsnames2")
    def get_conn():
        conn = cx_Oracle.connect(dsn="alias2")
        conn.ping()
        return conn

if __name__ == "__main__":
    db1 = Database1()
    db2 = Database2()

    conn1 = db1.get_conn()
    conn2 = db2.get_conn()

In my application I want to extract data from a database and load it in other database. For security reasons, I'd like to connect to the databases using wallets. Basically, I have an object that connects to the source database, makes a select and loads the data in memory and the I use another object that connects to the target database to insert the data. I have wallets to connect to both databases but can't find a way to have two objects that connect to each database when using wallets.

Do you have any suggestions?

@thiagodma thiagodma added the bug label Apr 27, 2021
@cjbj
Copy link
Member

cjbj commented Apr 27, 2021

See #553

@cjbj cjbj closed this as completed Apr 27, 2021
@cjbj cjbj added question and removed bug labels Apr 27, 2021
@thiagodma
Copy link
Author

Hi @cjbj, I saw this issue but I don't get how it solves my problem. The solution that @anthony-tuininga proposes in #485 expects an user and password but all I don't have it... Also, do you have a clue about when is this going to be solved in cx_Oracle? It seems weird that we should write that much code to be able to connect to different databases using two different wallets...

@cjbj
Copy link
Member

cjbj commented Apr 27, 2021

@thiagodma I don't believe whether you have or don't have credentials matters. I think the fundamental thing is that you need a single tnsnames.ora & sqlnet.ora files in the one directory. Then you need to make sure the different connect strings in that tnsnames.ora refer to your different wallets. (And use 21c client). Try it out and let me know. (And use 21c client)

The code Anthony has is just to save some manual effort for cloud wallet (where you download a zip from the cloud). If you are creating your own files, then you don't have to write any extra code: just make sure your connection descriptors use the correct wallet.

For background: This is not a cx_Oracle problem. Connectivity and security are several layers lower in the Oracle Client libraries. You'd have the same behavior with SQL*Plus.

@thiagodma
Copy link
Author

thiagodma commented Apr 28, 2021

Thank you for your answer, @cjbj . About the tnsnames.ora, should it be something like this?

(DESCRIPTION= (ADDRESS=(PROTOCOL=tcps)(HOST=salesserver)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=sales)) (SECURITY=(SSL_SERVER_DN_MATCH=TRUE)(SSL_SERVER_CERT_DN=cn=sales,cn=OracleContext,dc=us,dc=example,dc=com)(MY_WALLET_LOCATION=/tmp/oracle)))

If so, I'll try it with 21c client, I tried with 19c instant client and it didn't work tho.. Are you also suggesting for me to use the full client, not the instant client?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants