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




  • 【问题描述】
    启动应用的过程中,出现如下提示,说明应用无法连接到数据库。

    [ERROR] 2013-05-08 10:47:21,993 org.hibernate.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory (Listen
    er refused the connection with the followin
    g error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    The Connection descriptor used by the client was:
    rac1:1521:racdb
    )

    【处理过程】
    由于数据库是RAC环境,因此怀疑是应用jdbc的配置不适用于RAC环境。

    #hibernate config
    hibernate.dialect=org.hibernate.dialect.OracleDialect
    iam.jdbc.database=oracle
    iam.jdbc.driverClassName:oracle.jdbc.driver.OracleDriver
    iam.jdbc.url:jdbc:oracle:thin:@192.168.1.111:1521:username
    iam.jdbc.username:username
    iam.jdbc.password:password

    上面的写法不适用于RAC环境,因此要修改为下面的写法:

    #hibernate config
    hibernate.dialect=org.hibernate.dialect.OracleDialect
    iam.jdbc.database=oracle
    iam.jdbc.driverClassName:oracle.jdbc.driver.OracleDriver
    iam.jdbc.url:jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rac1)(PORT=1521))(LOAD_BALANCE=YES)(FAILOVER=YES)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=racdb)))
    iam.jdbc.username:username
    iam.jdbc.password:password

    【参考】
    If you have Java application and use JDBC to connect to Oracle database, typically you use the following format to connect:

    jdbc:oracle:thin:@<HOST>:<PORT>:<SID>

    However, this would not work if you have Oracle RAC database. Following is the correct JDBC connection string for connecting to a RAC database
    For 11gR1:
    jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=vipaddress_node1)(PORT=1521)) (ADDRESS=(PROTOCOL=TCP)(HOST=vipaddress_node2)(PORT=1521)) (LOAD_BALANCE=no)(FAILOVER=yes))(CONNECT_DATA=(SERVICE_NAME=SID.WORLD)))

    For 11gR2:
    jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=scan-address)(PORT=1521))(LOAD_BALANCE=YES)(FAILOVER=YES)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SID.WORLD)))

    Speak Your Mind

    *

    京ICP备14059771号-2