无法从其他计算机连接oracle数据库

时间:2015-12-30 07:09:53

标签: oracle networking oracle11g oracle-sqldeveloper database-administration

我有两台计算机,计算机A有IP(10.11.11.2),其中包含oracle数据库11g R2,而计算机B有IP(10.11.11.18)。我搜索了很多,并在Tnsnames.ora和listener.ora文件中进行了一些更改但无法连接。但是当我从客户端调整10.11.11.2时,它给了我OK输出。可以从客户端访问该平均数据库,但我无法使用Toad或Sqldeveloper连接数据库。

给出错误:      tns目前不知道所要求的服务

我的电脑A(10.11.11.2)tnsname.ora和listener.ora文件粘贴如下:

Tnsnames.ora文件

# tnsnames.ora Network Configuration File:     D:\app\Mobilityusr\product\11.2.0\dbhome_1\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)
    )
  )

listener.ora文件

# listener.ora Network Configuration File: D:\app\Mobilityusr\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\app\Mobilityusr\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:D:\app\Mobilityusr\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.11.2)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\app\Mobilityusr

我的电脑B(10.11.11.18)tnsname.ora和listener.ora文件粘贴如下:

tnsnames.ora文件

# tnsnames.ora Network Configuration File: D:\app\product\11.2.0\dbhome_1\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)
    )
  )

的listener.ora

# listener.ora Network Configuration File: D:\app\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\app\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS =     "EXTPROC_DLLS=ONLY:D:\app\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\app

还附加了从计算机B到oracle数据库(安装在Comupter A上)的映像: enter image description here

还附加了错误图像 enter image description here

3 个答案:

答案 0 :(得分:2)

经过大量研究后我解决了这个问题。我也必须与你分享,以便任何有这个问题的人都可以轻松解决。

Listener.ora文件用于监听请求。如果我们想从另一台计算机访问数据库,我们必须在listener.ora中添加两个条目(一个用于SID,另一个用于机器IP地址)。

计算机A文件(listener.ora和tnsnames.ora)设置如下:

<强> LISTENER.ORA

# listener.ora Network Configuration File: D:\app\Mobilityusr\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\app\Mobilityusr\product\11.2.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS =     "EXTPROC_DLLS=ONLY:D:\app\Mobilityusr\product\11.2.0\dbhome_1\bin\oraclr11.dll")
    )  
    (SID_DESC =
     (GLOBAL_DBNAME = orcl)
     (ORACLE_HOME = D:\app\Mobilityusr\product\11.2.0\dbhome_1)
     (SID_NAME = orcl)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.11.11.2)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = D:\app\Mobilityusr

SID_LIST_LISTENER包含两个条目,首先SID_DESC是默认条目,我们必须添加第二个SID_DESC才能识别orcl SID否则在从其他机器连接数据库时Sqldeveloper或toad或sqlplus将给出以下错误: 错误:sid目前不知道

现在,Listener默认为localhost包含两个条目,我们必须添加包含服务器机器IP的第二个条目。通过此条目服务器上的数据库可以监听包含此IP地址的连接将连接到服务器数据库。否则将无法连接数据库。

注意:您可以使用这些配置,但不要忘记更改IP和oracle_home路径

和tnsnames.ora文件用于定义任何数据库参数(SID,PORT,HOST)的别名。但是,不必将tnsnames.ora更改为连接服务器和客户端,因此我不会修改位于服务器计算机上的tnsnames.ora。

计算机B tnsnames.ora与上述问题相同。 计算机B listener.ora与上述问题相同。

要点: 您只需要更改位于服务器计算机上的listener.ora文件(Oracle_home / network / admin /)。并在SID_LIST_LISTENER中添加两个条目以添加SID详细信息,并在LISTENER中添加第二个条目以添加计算机IP描述。

同时检查环境变量(ORACLE_UNQNAME,ORACLE_SID,ORACLE_HOME,TNS_ADMIN等)

更重要的一点您必须检查Listener服务是否已启动并正在运行 使用这些命令(打开CMD并输入):

** lsnrctl status **

** lsnrctl start **

** lsnrctl stop **

当你更改listener.ora文件时,你必须停止然后启动lsnrctl服务以改变效果。

答案 1 :(得分:0)

在SQLDeveloper中,不要指定SID,而是选择Service Name。

答案 2 :(得分:0)

我遇到了同样的问题,但是对于Oracle 12C却遇到了很多麻烦。终于使它与几乎类似的解决方案一起工作。

我的数据库服务器位于192.168.1.165上,端口为1526。 还必须在Windows服务器防火墙中打开端口1526。

# listener.ora Network Configuration File: G:\app\db12\product\12.1.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = G:\app\db12\product\12.1.0\dbhome_1)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:G:\app\db12\product\12.1.0\dbhome_1\bin\oraclr12.dll")
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
     (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1526))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1526))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1526))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.165)(PORT = 1526))
    )
  )