ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

摘要: This is caused by the requested SID doesn’t exist in {ORACLE_HOME}/network/admin/tnsnames.ora

This is caused by the requested SID doesn’t exist in {ORACLE_HOME}/network/admin/tnsnames.ora

P.S Tested with Oracle database 19c with ojdbc8.jar

1. JDBC

	try (Connection conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:xe", "system", "password")) {
           //...
	} catch (SQLException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();

Output:

SQL State: 66000
Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

The SID xe doesn’t exist in ORACLE_HOME/network/admin/tnsnames.ora

2. tnsnames.ora

Sample.

C:\{ORACLE_HOME}\NETWORK\ADMIN\tnsnames.ora
# tnsnames.ora Network Configuration File: C:\{ORACLE_HOME}\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)

In above tnsnames.ora sample, the SID is ORCL

To fix it, update the code:

	try (Connection conn = DriverManager.getConnection(
		"jdbc:oracle:thin:@localhost:1521:orcl", "system", "password")) {
		//...
	} catch (SQLException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();

上一篇: Java Events 2019
下一篇: How to Uninstall Oracle Database 19c on Windows
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号