您现在的位置:主页 > 数据库 > MS_SQL >

在Oracle里设置访问多个SQLServer

来源:建站吧 责任编辑:Jzq8 发表时间:2011-12-23 点击:
 如何在Oracle里设置访问多个SQL Server数据库?假设我们要在ORACLE里同时能访问SQL Server里默认的pubs和Northwind两个数据库。   

  1、在安装了ORACLE9i Standard Edition或者ORACLE9i Enterprise Edition的windows机器上(IP:192.168.0.2), 产品要选了透明网关(Oracle Transparent Gateway)里访问Microsoft SQL Server数据库   

  $ORACLE9I_HOME\tg4msql\admin下新写initpubs.ora和initnorthwind.ora配置文件.

  initpubs.ora内容如下:

  HS_FDS_CONNECT_INFO="SERVER=SQLSERVER_HOSTNMAE;DATABASE=pubs"

  HS_DB_NAME=pubs

  HS_FDS_TRACE_LEVEL=OFF

  HS_FDS_RECOVERY_ACCOUNT=RECOVER

  HS_FDS_RECOVERY_PWD=RECOVER

  initnorthwind.ora内容如下:

  HS_FDS_CONNECT_INFO="SERVER=sqlserver_hostname;DATABASE=Northwind"

  HS_DB_NAME=Northwind

  HS_FDS_TRACE_LEVEL=OFF

  HS_FDS_RECOVERY_ACCOUNT=RECOVER

  HS_FDS_RECOVERY_PWD=RECOVER  

  $ORACLE9I_HOME\network\admin 下listener.ora内容如下:

  LISTENER =

   (DESCRIPTION_LIST =

   (DESCRIPTION =

   (ADDRESS_LIST =

   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))

   )

   )

   )  

  SID_LIST_LISTENER =

   (SID_LIST =

   (SID_DESC =

   (GLOBAL_DBNAME = test9)

   (ORACLE_HOME = d:\oracle\ora92)

   (SID_NAME = test9)

   )

   (SID_DESC=

   (SID_NAME=pubs)

   (ORACLE_HOME=d:\Oracle\Ora92)

   (PROGRAM=tg4msql)

   )

   (SID_DESC=

   (SID_NAME=northwind)

   (ORACLE_HOME=d:\Oracle\Ora92)

   (PROGRAM=tg4msql)

   )

   )  

  重启动这台做gateway的windows机器上(IP:192.168.0.2)TNSListener服务.   

  (凡是按此步骤新增可访问的SQL Server数据库时,TNSListener服务都要重启动)   

  2、ORACLE8I,ORACLE9I的服务器端配置tnsnames.ora, 添加下面的内容:   

  pubs =

   (DESCRIPTION =

   (ADDRESS_LIST =

   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))

   )

   (CONNECT_DATA =

   (SID = pubs)

   )

   (HS = pubs)

   )

  

  northwind =

   (DESCRIPTION =

   (ADDRESS_LIST =

   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))

   )

   (CONNECT_DATA =

   (SID = northwind)

   )

   (HS = northwind)

   )

   保存tnsnames.ora后,在命令行下

   tnsping pubs

   tnsping northwind  

  出现类似提示,即为成功  

  Attempting to contact (DESCRIPTION = (ADDRESS_LIST =

  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)

  (PORT = 1521))) (CONNECT_DATA = (SID = pubs)) (HS = pubs))

  OK(20毫秒)

  Attempting to contact (DESCRIPTION = (ADDRESS_LIST =

   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)

  (PORT = 1521))) (CONNECT_DATA = (SID = northwind)) (HS = northwind))

  OK(20毫秒)  

  设置数据库参数global_names=false。   

  设置global_names=false不要求建立的数据库链接和目的数据库的全局名称一致。global_names=true则要求, 多少有些不方便。   

  oracle9i和oracle8i都可以在DBA用户下用SQL命令改变global_names参数   

  alter system set global_names=false;

  建立公有的数据库链接:   

  create public database link pubs

  connect to testuser identified by testuser_pwd using 'pubs';

  create public database link northwind

  connect to testuser identified by testuser_pwd using 'northwind';

  (假设SQL Server下pubs和northwind已有足够权限的用户登陆testuser,

  密码为testuser_pwd)  

  访问SQL Server下数据库里的数据:   

  select * from stores@pubs;

  ...... ......

  select * from region@northwind;

  ...... ......  

  3、使用时的注意事项  

  ORACLE通过访问SQL Server的数据库链接时,用select * 的时候字段名是用双引号引起来的。

  例如:   

  create table stores as select * from stores@pubs;

  select zip from stores;

  ERROR 位于第 1 行:

  ORA-00904: 无效列名

  select "zip" from stores;

  zip

  -----

  98056

  92789

  96745

  98014

  90019

  89076  

  已选择6行。   

  用SQL Navigator或Toad看从SQL Server转移到ORACLE里的表的建表语句为:  

  CREATE TABLE stores

   ("stor_id" CHAR(4) NOT NULL,

   "stor_name" VARCHAR2(40),

   "stor_address" VARCHAR2(40),

   "city" VARCHAR2(20),

   "state" CHAR(2),

   "zip" CHAR(5))

   PCTFREE 10

   PCTUSED 40

   INITRANS 1

   MAXTRANS 255

   TABLESPACE users

   STORAGE (

   INITIAL 131072
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片

今日头条

更多>>

推荐图文

  • SQL Server 2005 安全设置教程
  • SQL Server2000连接中的常见错误
  • 剖析SQLServer查询通知之基础篇
  • SQLServer数据加密技术应用研究
  • SQL教程:SQLServer备份和灾难恢复
  • 使用publishing转移MSSQL数据
  • SQL集合函数中利用casewhenthen技巧
  • SQLServer数据挖掘中的几个问题之理解内容类型
  • 数据库置疑?几步搞定SQL数据库修复
Alexa - 客户服务 - 联系方法 - 招聘信息 - 友情链接 - 网站地图 - TAG标签 - RSS订阅
Copyright © 2010-2012 JZQ8.COM. 建站吧|建站去吧 版权所有
冀ICP备09002514号
冀ICP备09002514号 网络报警 企业法人营业执照 中国互联网协会 支付宝付款 网银在线付款