Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

EF Core 3.1 - Exception when trying to use TnsAdmin

TridusAug 26 2020 — edited Sep 18 2020

I'm getting the following error when trying to set a TnsAdmin path: OracleConfiguration.TnsAdmin = @"c:\oracle\client\19c\network\admin";

System.IO.FileNotFoundException

  HResult=0x80070002

  Message=Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

  Source=Oracle.ManagedDataAccess

  StackTrace:

   at OracleInternal.Network.LDAP..ctor(SqlNetOraConfig SNOConfig, Hashtable ObLdapHT)

   at OracleInternal.Network.AddressResolution.SetNewLDAP(Hashtable SQLNetHT, Hashtable LdapHT)

   at Oracle.ManagedDataAccess.Client.OracleConfiguration.set_TnsAdmin(String value)

   at GNB.ELG.WellVoucher.Website.External.Startup.ConfigureServices(IServiceCollection services) in C:\workarea\Startup.cs:line 32

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)

   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)

   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()

   at Microsoft.Extensions.Hosting.HostBuilder.Build()

   at GNB.ELG.WellVoucher.Website.External.Program.Main(String[] args) in C:\workarea\Program.cs:line 16

This is a brand new ASP.net Core 3.1 project that isn't really doing much of anything yet. Scaffolding the dbcontext from the database works fine, however trying to run the project results in this error.

I've got the same thing in an ASP.net Core 2 project and that works without issue pointing to the same path, so I'm not sure what changed. I don't have an ldap.ora defined at all, and sqlnet.ora is as follows:

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES)

SQLNET.CRYPTO_SEED = "X"

NAMES.DEFAULT_DOMAIN = X

NAME.DEFAULT_ZONE = X

Thanks

Message was edited by: Tridus (removed beta tag as it is still an issue in production)

This post has been answered by Alex Keh-Oracle on Oct 22 2020
Jump to Answer

Comments

Start by checking that SQL*Plus (not SQL Developer) can connect.
Then try a Python program that calls cx_Oracle directly (not using Django).
This post has some useful tips that apply to all apps connecting to a remote DB: https://www.thatjeffsmith.com/archive/2014/09/ora-12545-12541-12514-01017/

Roland Mueller

Before running Django app you should of course check
whether the listener is up & running in DB machine
whether you can connect from host where django app is running to DB server+DB port. DB port is 1521 by default, but in the text I saw 1539 mentioned
connection check can be done using nmap or simply the telnet client app: 'telnet DB_HOST PORT'

Shouldn't connecting to Oracle DB using the default port 1521 in this way in settings.py?
variables DB_HOSTNAME and SID_OR_SERVICE are set in same settings.py
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': DB_HOSTNAME + ':1521/' + SID_OR_SERVICE,
'USER': 'user',
'PASSWORD': 'pass',
}
With other port 1521 has to be replaced.

One note: 'SID_OR_SERVICE' should be 'SERVICE' since the 'easy connect' syntax doesn't support SIDs.
A couple of recent blog posts might be of interest:
https://blogs.oracle.com/opal/connecting-to-oracle-cloud-autonomous-database-with-django
https://blogs.oracle.com/opal/running-oracle-database-backed-django-web-applications-on-apache

Tony007

this my setting
"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 2.0.2.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '39tl#ywdu(^i#u2f-rosga7vn)&uchp^h96myvl4wo80a=+4g*'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'oauth2_provider',
'rest_framework',

]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'corsheaders.middleware.CorsPostCsrfMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'mysite.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'dbname',
'USER': 'username',
'PASSWORD': 'password',
'PORT': '1539',
'HOST': '199.154.7.188'
}
}

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

AUTH_USER_MODEL = 'accounts.User'

CORS_ORIGIN_ALLOW_ALL = True

OAUTH2_PROVIDER = {

this is the list of available scopes

'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}

REST_FRAMEWORK = {

Use Django's standard `django.contrib.auth` permissions,

or allow read-only access for unauthenticated users.

'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
)
}

telnet 199.128.2.111:1539
telnet: could not resolve 192.168.8.123:1539/telnet: Name or service not known

If you are having network issues, install SQL*Plus (not SQL Developer) on the machine where you run Python and make sure you can connect to the database using that. Then the same connection string will be usable in Django (assuming it runs in the same environment)

1 - 5

Post Details

Added on Aug 26 2020
13 comments
1,137 views