gpt4 book ai didi

django - 如何解决没有 SID 的 ORA-12505

转载 作者:行者123 更新时间:2023-12-01 19:37:07 24 4
gpt4 key购买 nike

我正在做一个 django 项目,当我尝试连接到 Oracle 数据库时,我收到了这条消息:

DataBaseError: ORA-12505: TNS:listener does not currently know of SID given inconnect descriptor

All the answers online have said "You need to make sure you have the correct SID", so I asked the person at my work who manages all the databases and he said "We don't have SID's for these guys. We use service names instead."

I can access the db via the command line, but trying to get django to do this is driving me crazy. Any help would be greatly appreciated. Thanks

EDIT: Here is my settings.py file. It's not too interesting... this is a fresh project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = ( ,
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': '',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'a_host',
'PORT': '1521',
}
}


TIME_ZONE = 'Europe/London'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = ''

MEDIA_URL = ''

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (

)


STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)


TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'sandbox.urls'

WSGI_APPLICATION = 'sandbox.wsgi.application'

TEMPLATE_DIRS = (

)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

最佳答案

如果您具有 DBA 访问权限,则可以通过以下方式获取 SID:

从 V$THREAD 中选择实例;

通常,它与您的 TNSNAMES.ORA 文件中使用的名称相同(在下面的例子中是 MYDB)。

 MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dbserver.mynetwork)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = MYDB.mynetwork)
)
)

所以设置应该是:

 DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'MYDB',
'USER': 'a_user',
'PASSWORD': 'a_password',
'HOST': 'dbserver.mynetwork',
'PORT': '1521',
}
}

关于django - 如何解决没有 SID 的 ORA-12505,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com