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.

Oracle.ManagedDataAccess.Core beta2 Oracle.ManagedDataAccess.Types.TimeStamp InvalidCastException Er

93aec6ef-f91d-45ba-95c5-35c685adb506Apr 20 2018 — edited Aug 27 2018

When using the Oracle.ManagedDataAccess.Core(1.12.0-beta2) 

I get the following error.   It goes into the Catch block, during the Open connection.

The below is what ends in Exception.InnerException (converted to String). 

"System.TypeInitializationException: The type initializer for 'OracleInternal.ServiceObjects.OracleConnectionImpl' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Oracle.ManagedDataAccess.Types.TimeStamp' threw an exception. ---> System.InvalidCastException: Object must implement IConvertible.\r\n   at OracleInternal.Common.OracleTimeZone.GetInstance()\r\n   at Oracle.ManagedDataAccess.Types.TimeStamp..cctor()\r\n   --- End of inner exception stack trace ---\r\n   at Oracle.ManagedDataAccess.Types.TimeStamp.InitializelatestTZversion()\r\n   at OracleInternal.ServiceObjects.OracleConnectionImpl..cctor()\r\n   --- End of inner exception stack trace ---\r\n   at OracleInternal.ServiceObjects.OracleConnectionImpl..ctor()"

Is anyone else seeing this error?

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
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 24 2018
Added on Apr 20 2018
8 comments
2,868 views