Forum Stats

  • 3,767,820 Users
  • 2,252,720 Discussions
  • 7,874,337 Comments

Discussions

Getting an error while connecting oracle DB from Python : cx_Oracle.DatabaseError: ORA-12154: TNS:co

DINESH  EDVIN
DINESH EDVIN Member Posts: 50
edited Oct 25, 2018 1:01PM in Python

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/[email protected]/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/[email protected]/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/[email protected]/XE')

  print(conn)

Note : attached is the TNS file content. Please refer

Thanks,

DineshTNS.jpg

Best Answer

Answers