我在尝试通过监听器连接到Oracle数据库XE时遇到问题:
sqlplus system/my_password@XE
我收到以下错误:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
我使用的是Ubuntu 12.10和Oracle Express Edition 11g。
我的主要目标是将java + oracle db与jdbc连接,但是我得到了同样的错误。
这是我的listener.ora
# listener.ora Network Configuration File:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = watson)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
和tnsnames.ora
# tnsnames.ora Network Configuration File:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = watson)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
和
lsnrctl service
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 04-FEB-2014 17:01:44
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
The command completed successfully
答案 0 :(得分:2)
假设您的数据库即使在侦听器运行一段时间后仍未注册,听起来您的local_listener
参数未明确设置,因此您的数据库正在尝试注册on a default address;并且因为它没有注册,所以它所使用的任何地址似乎与听众不同。
假设watson
正在解析一个有用的外部IP地址,如果你能够从你的盒子外面得到那个TNS错误,那么你可以告诉数据库使用相同的地址来注册:
alter system set local_listener = '(ADDRESS=(PROTOCOL=TCP)(HOST=watson)(PORT=1521))' scope=memory;
alter system register;
如果有效且lsnrctl services
现在显示XE
并且您对此感到满意,则可以将memory
更改为both
并重新执行so it persists across the next DB restart }。
或者,如果您只尝试在同一个框内进行连接,则watson
可能会解析为无用的内容,例如127.0.0.1,如果它已设置为在/etc/hosts
中执行此操作;或者您的/etc/hosts
地址可能与您的DNS条目不一致。您可以将listener.ora
和tnsnames.ora
更改为“正确的”FQDN或IP地址,只要该匹配数据库认为的网络名称。
答案 1 :(得分:0)
tnsnames.ora很好,它用于sqlplus客户端。 listener.ora并不好。键入lsnrctl服务时,您缺少XE服务 很难相信你必须设置listener.ora才能安装Oracle Express。
以下是我测试VM的一个示例。
Service "PEXPROC" has 1 instance(s).
Instance "PEXPROC", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Service "ocmdb" has 1 instance(s).
Instance "ocmdb", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:29 refused:0
LOCAL SERVER
The command completed successfully
我在listener.ora中的示例段
SID_LIST_LISTENER_OCM =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ocmdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = ocmdb)
)
)
答案 2 :(得分:0)
我不得不在Windows服务中重新启动OracleServiceXE服务,并且该服务再次正常工作。