Reputation: 2907
Trying to connect to the Oracle DB via settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'Hostname:Port/Service name not SID',
'USER': 'Username',
'PASSWORD': 'Password',
}
}
Based on what I have found online, that is supposed to be how I connect to an Oracle DB via service name if I do not have SID. But I still get the error django.db.utils.DatabaseError: ORA-12154: TNS:could not resolve the connect identifier specified
If I however forgo placing these details in the settings.py
and I just use the connection strings provided by cx_Oracle
,
dsn_tns = cx_Oracle.makedsn('Hostname', 'Port',
service_name='Service name not SID')
connection = cx_Oracle.connect('Username', 'Password', dsn_tns)
I connect just fine. Is there a new syntax to connect to the service name for settings.py? Is there a point in trying to connect via settings.py if I can simply connect via the connection strings?
Upvotes: 6
Views: 4221
Reputation: 1
Try this.
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EHS_CONF_PATH = os.path.join(BASE_DIR, 'arquivo.conf')
DATABASES = {
'default': {
'ENGINE': os.environ['DB_ENGINE'],
'NAME': os.environ['DB_NAME'],
'HOST': os.environ.get('DB_HOST', 'localhost'),
'PORT': os.environ.get('DB_PORT', '1521'),
'USER': os.environ.get('DB_USER', 'user'),
'PASSWORD': os.environ.get('DB_PASS', "pass")
}
}
arquivo.conf
DB_NAME=XE
DB_USER=user
DB_PASS=pass
DB_HOST=10.7.0.140 <-- ip host
DB_PORT=1521
DB_ENGINE=django.db.backends.oracle
I had a problem when my password contained '@'
Upvotes: 0