2016-04-21 60 views
0

我正嘗試使用Ruby on Rails Rake命令遷移到Oracle數據庫。我database.yml文件包含以下內容:Ruby on Rails Rake命令導致Oracle TNS錯誤

development: 
    adapter: oracle 
    database: album_development 
    sid: orc1   
    username: system 
    password: root 

在我的電腦我已經設​​置ORACLE_SID=orcl.

當我運行耙,遷移,我得到以下錯誤:

rake aborted! 
The driver encountered an error: java.sql.SQLException: Listener refused the connection with the following error: 
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor 

你能告訴我,如果我需要修改我的listener.ora文件才能使其工作?我listener.ora文件如下:

SID_LIST_LISTENER = 
    (SID_LIST = 
    (SID_DESC = 
     (SID_NAME = PLSExtProc) 
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server) 
     (PROGRAM = extproc) 
    ) 
    (SID_DESC = 
     (SID_NAME = CLRExtProc) 
     (ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server) 
     (PROGRAM = extproc) 
    ) 
) 

LISTENER = 
    (DESCRIPTION_LIST = 
    (DESCRIPTION = 
     (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
     (ADDRESS = (PROTOCOL = TCP)(HOST = Lenovo-PC)(PORT = 1521)) 
    ) 
) 

DEFAULT_SERVICE_LISTENER = (XE) 

的LSNRCTL status命令的輸出如下:

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) 
STATUS of the LISTENER 
------------------------ 
Alias      LISTENER 
Version     TNSLSNR for 32-bit Windows: Version 11.2.0.2.0 - Production 
Start Date    21-APR-2016 11:14:15 
Uptime     0 days 0 hr. 7 min. 43 sec 
Trace Level    off 
Security     ON: Local OS Authentication 
SNMP      OFF 
Default Service   XE 
Listener Parameter File C:\oraclexe\app\oracle\product\11.2.0\server\network\admin\listener.ora 
Listener Log File   C:\oraclexe\app\oracle\diag\tnslsnr\Lenovo-PC\listener\alert\log.xml 
Listening Endpoints Summary... 
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc))) 
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Lenovo-PC)(PORT=1521))) 
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Lenovo-PC)(PORT=8080))(Presentation=HTTP)(Session=RAW)) 
Services Summary... 
Service "CLRExtProc" has 1 instance(s). 
    Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service... 
Service "PLSExtProc" has 1 instance(s). 
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... 
Service "XEXDB" has 1 instance(s). 
    Instance "xe", status READY, has 1 handler(s) for this service... 
Service "xe" has 1 instance(s). 
    Instance "xe", status READY, has 1 handler(s) for this service... 
The command completed successfully 

誰能幫助/提個建議嗎?

+0

你有沒有嘗試連接到xe而不是orcl例如sid:xe –

+0

是的,我嘗試過使用sid:xe它也行不通 – Sean

+0

typo orc1 \ orcl ??? –

回答

0

首先你可以檢查數據庫是通過使用TNSPING命令訪問

e.g:TNSPING xe

它可能是你用了一個,而不是一個L SID:ORC1應該是SID:ORCL吧?

+0

Kevin, 感謝您的回覆。我跑了命令,結果如下;適用於32位Windows的TNS Ping實用程序:版本11.2.0.2.0 - 2016年4月21日的生產時間13:04:16 版權所有(c)1997,2010,Oracle。版權所有。 使用參數文件: C:\ oraclexe \應用\ ORACLE \產品\ 11.2.0 \服務器\網絡\管理員\ SQLNET.ORA 用於TNSNAMES適配器來解析別名 試圖聯繫(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = Lenovo-PC)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XE))) OK(10毫秒) – Sean

+0

如果將database.yml更改爲指向xe而不是orcl做到了嗎? –

0

Kevin,

感謝您的幫助。我改變了我的database.yml到:

development: 

    adapter: oracle 
    database: xe 
    username: system 
    password: root 

這讓我連接到數據庫。我現在有另一個問題,但我想我可以解決這個問題。親切的問候,肖恩