0

I am trying to connect to oracle DB using the below program and somehow I am getting the error. I tried to turn off the firewall and check there is no luck. I did check the port number from the tnsnames.ora file for that connection and I am using the same one. I am using the IPv4 address by checking on ipconfig from command prompt. Any help would be greatly appreciated.

There is a problem with Oracle DPY-6005: cannot connect to database. Connection failed with "[WinError 10061] No connection could be made because the target machine actively refused it"

import oracledb

# Create a table in Oracle database
try:
    print("############")
    #con = oracledb.connect('userid/password@XXX.XXX.XXX.XXX/ORCL')
    con = oracledb.connect(user="userid", password='password',
                                  host="XXX.XXX.XXX.XXX", port=1521, service_name="orcl.lan")
    print("############")
    print(con.version)

    # Now execute the sqlquery
    cursor = con.cursor()

    # Creating a table employee
    cursor.execute("create table employee(empid integer primary key, name varchar2(30), salary number(10, 2))")

    print("Table Created successfully")

except oracledb.DatabaseError as e:
    print("There is a problem with Oracle", e)

# by writing finally if any error occurs
# then also we can close the all database operation
finally:
    if cursor:
        cursor.close()
    if con:
        con.close()
John
  • 1
  • 3
  • Have you ever tried by replacing `oracledb` with `cx_Oracle` library ? – Barbaros Özhan Jul 31 '22 at 18:28
  • cx_oracle is not working with Python3.8. So i have to replace with oracledb – John Jul 31 '22 at 19:08
  • No, it works with 3.8 like the other versions of python3 – Barbaros Özhan Jul 31 '22 at 19:12
  • I am getting below error while using cx_Oracle There is a problem with Oracle DPI-1047: Cannot locate a 64-bit Oracle Client library: "The specified module could not be found". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help – John Jul 31 '22 at 19:14
  • Did you set the environment variables of PATH and PYTHONPATH after downloading the compatible version of instantclient ..? – Barbaros Özhan Jul 31 '22 at 19:28
  • Yes, I have done it – John Aug 01 '22 at 00:15
  • This might be related to this issue: https://stackoverflow.com/questions/20437701/winerror-10061-no-connection-could-be-made. Specifically, check proxy settings! – Anthony Tuininga Aug 01 '22 at 18:02
  • @BarbarosÖzhan There's no reason to replace python-oracledb with cx_Oracle, since the former is just the renamed, major release of the latter. If there is anything to try it is to enable the Thick mode of python-oracledb, since this uses the same code paths as the older cx_Oracle version. – Christopher Jones Aug 01 '22 at 21:27
  • @ChristopherJones I didn't use, and don't know about `oracledb` but `cx_Oracle`, so suggested that as an alternative to be tried. Thanks for the information. – Barbaros Özhan Aug 01 '22 at 21:59
  • 1
    @BarbarosÖzhan no problems. For the record, see the [python-oracledb release announcement](https://cjones-oracle.medium.com/open-source-python-thin-driver-for-oracle-database-e82aac7ecf5a). Info on the Thin & Thick modes is in the [doc](https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#initializing-python-oracledb). – Christopher Jones Aug 02 '22 at 03:05

0 Answers0