Recommended way to connect Oracle Databases

1,856 views
Skip to first unread message

vizcayno

unread,
Jan 5, 2007, 4:05:19 PM1/5/07
to Django developers
Hello:
Assuming I have an Oracle database with next connection info:
user = scott
pass = tiger
host = Oracle host Name or IP address
ORCL = Name of database
with no tnsnames.ora file

1) From command line I can do:
sqlplus scott/tiger@host/ORCL

2) From a Python script:
import cx_Oracle
connection = cx_Oracle.connect("scott", "tiger", "host/ORCL")

3) And to get it working under Django I put the next in the settings.py
file:
DATABASE_ENGINE = 'oracle'
DATABASE_NAME = 'ORCL'
DATABASE_USER = 'scott'
DATABASE_PASSWORD = 'tiger'
DATABASE_HOST = 'host'
DATABASE_PORT = ''

But I get error:
cx_Oracle.DatabaseError: ORA-12154: TNS:could not resolve the connect
identifier specified

Only if I change DATABASE_NAME to 'host/ORCL' I can get the right
connection.

Next line code exists in Oracle base.py script:
conn_string = "%s/%s@%s" % (settings.DATABASE_USER,
settings.DATABASE_PASSWORD, settings.DATABASE_NAME)

Do your consider convenient to change the code to:
conn_string = "%s/%s@%s/%s" % (settings.DATABASE_USER,
settings.DATABASE_PASSWORD, settings.DATABASE_HOST,
settings.DATABASE_NAME)
??

Or do you have any recommendation for my case?

Thanks for your attention.

Michael van der Westhuizen

unread,
Jan 5, 2007, 4:20:37 PM1/5/07
to django-d...@googlegroups.com
Hi,

On 1/5/07, vizcayno <pretori...@hotmail.com> wrote:
>
[snip discussion of "lite" connection strings vs. TNS]

To properly specify a database connection you'd also need provision
for a port number (the listener port). While that seems like a
reasonable idea, TNS is a better mechanism as it abstracts the
underlying Net8/Net9 transport from the naming of connections.

I'd just go with tnsnames - you can always create a file called
".tnsnames.ora" in your home directory with whatever TNS configuration
you want.

If you don't want to put a tnsnames file in your home directory,
bundle a tnsnames.ora with your app and set the TNS_ADMIN environment
variable to point to the directory.

Michael

Reply all
Reply to author
Forward
0 new messages