4 Replies Latest reply on Oct 25, 2018 5:01 PM by DINESH EDVIN

    Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified

    DINESH EDVIN

      Hi,

       

       

      I am trying to connect the Oracle database from Python IDLE with below code but getting an error.

      Can anyone help me on this.

      import cx_Oracle

       

       

      conn = cx_Oracle.connect('hr/hr@Sony-PC/XE')

      print(conn)

       

       

      Error:

      Traceback (most recent call last):

        File "D:/Python/25_10(2).py", line 3, in <module>

          conn = cx_Oracle.connect('hr/hr@Sony-PC/XE')

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

       

       

      I have done the below prerequisites before executing the code.

      1.Installed Oracle 11 g 64 bit Express edition.(created username/password: hr/hr)

      2.Installed Python 3.7.1 64 bit.(automatically the PATH has been set)

      3.Installed the cx_Oracle package using below command.

        python -m pip install cx_Oracle --upgrade pip

        (currently this is having 18.1 version)

      4.Downloaded the Oracle Instant client 64 bit and set the PATH in system variable. ;C:\instantclient-basic-windows.x64-11.2.0.4.0\instantclient_11_2

      5.Installed the Microsoft Windows Redistributables for client library.

      6.Tried executing the below code but getting error.

        import cx_Oracle

        conn = cx_Oracle.connect('hr/hr@Sony-PC/XE')

        print(conn)

      Note : attached is the TNS file content. Please refer

       

       

      Thanks,

      DineshTNS.jpg