当前位置:数据库 > Oracle >>

[oracle]Pro*c链接oracle数据库

[oracle]Pro*c链接oracle数据库
 
一程序链接oracle数据库:
 
    EXEC SQL CONNECT :DbUser IDENTIFIED BY :DbPasswd USING :DbServer;

 

 
其中DbServer为UCRC
 
    查文件未发现一IP地址的定义。如何链接的远端数据库?
 
------------------------------------------------------
 
tnsnames.ora 文件的存放路径为 $ORACLE_HOME/network/admin 以下是一个示例
 
  OID.LOCALDOMAIN =
  (DESCRIPTION =
   (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT =
  1521))
   )
   (CONNECT_DATA =
   (SERVICE_NAME = oid)
   )
  )
  CAMS.LOCALDOMAIN =
  (DESCRIPTION =
   (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT =
  1521))
   )
   (CONNECT_DATA =
   (SERVICE_NAME = cams)
   )
  )
  INST1_HTTP.LOCALDOMAIN =
  (DESCRIPTION =
   (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT =
  
  1521))
   )
   (CONNECT_DATA =
   (SERVER = SHARED)
   (SERVICE_NAME = MODOSE)
   (divSENTATION = http://admin)
   )
   )
  EXTPROC_CONNECTION_DATA.LOCALDOMAIN =
   (DESCRIPTION =
   (ADDRESS_LIST =
   (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
   )
   (CONNECT_DATA =
   (SID = PLSExtProc1)
   (divSENTATION = RO)
   )
   )

 

    
说明
  tnsnames.ora 文件中定义一个或多个网络服务 net service cams 实例对应的网络服务为
  CAMS.LOCALDOMAIN =
  (DESCRIPTION =
   (ADDRESS_LIST =
   (ADDRESS =
   (PROTOCOL = TCP)
   (HOST = localhost.localdomain)
   (PORT = 1521))
   )
   (CONNECT_DATA =
   (SERVICE_NAME = cams)
   )
  )

 

  注意 这里 ADDRESS项包含三个子参数
  
  PROTOCOL :默认协议TCP
  
  HOST :ip地址
  
  PORT:端口,默认1521
  
  CAMS.LOCALDOMAIN为数据名
  
  要确保在监听文件中也有对应的一个 ADDRESS 项也包含同样的三个子参
  数 并且子参数的值对应都相等 另外 这里 SERVICE_NAME 的值必需确
  保与监听文件中某 SID_DESC项下的 SID_NAME参数的值相等
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,