Forum Stats

  • 3,727,354 Users
  • 2,245,375 Discussions


cx_Oracle: Connection failure after switch/restore of TNS_ADMIN

User_JQKIR Member Posts: 4 Red Ribbon
edited June 2020 in Python

I’m having trouble with cx_Oracle.connect when using 2 different TNS_ADMIN places. I’ve reproduced the problem in a small test script, which switches TNS_ADMIN, makes a wallet connection ; restores TNS_ADMIN, and then attempts to make a second connection to a different DB, which fails.

needTnsSwitch   = True

makeWalletCxn   = True

username        = "*****"

password        = "******"

service         = "*********"

encoding        = "UTF-8"

if needTnsSwitch:

        saveTns         = os.environ["TNS_ADMIN"]

        walletTns       = os.environ["WALLET_ADMIN_TNS"]

        os.environ["TNS_ADMIN"] = walletTns

        if makeWalletCxn:

                wcxn    = cx_Oracle.connect ("/@*****")


        os.environ["TNS_ADMIN"] = saveTns

otherCxn        = cx_Oracle.connect (username, password, service, encoding =  encoding)

With both Booleans True, the 2nd connect  fails with:

> ./test-TnsSwitch

Traceback (most recent call last):

  File "./test-TnsSwitch", line 25, in <module>

    otherCxn    = cx_Oracle.connect (username, password, service, encoding =  encoding)

cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

If I set makeWalletCxn to False, or needTnsSwitch to False, the connection assigned to “otherCxn” works fine.

>  ./test-TnsSwitch

otherCxn: <cx_Oracle.Connection to *****@*******&gt;

So it would appear that the 1st connect is changing/setting something internally in cx_Oracle which affects the second connection attempt, even though TNS_ADMIN has been restored to its original value.

Any ideas? Is this a bug in cx_Oracle?


Best Answer


Sign In or Register to comment.