1、Oracle10g 通过透明网关访问 SqlServer-2008 R2一、 准备A 机器:操作系统:Windows Server 2003 R2 32 位安装数据库:Oracle Database 10g 第 2 版 (10.2.0.3.0)安装路径:D:oracleproduct10.2.0db_1安装 10g 数据库透明网关:10201_gateways_win32安装路径:D:appasusoracleproduct10.2.0tg_1B 机器:192.168.1.103操作系统:Windows 7 旗舰版安装数据库:SQL Server 2008 R2 64 位*:网关和 SQL 数
2、据库在一起,便于管理。也可单独安装一台机器。二、 配置B 机器上安装了 SQL 和透明网关后, 在安装目录下D:appasusoracleproduct10.2.0tg_1tg4msqladmin 下新建 init文件,这里我沿用 inittg4msql,所以 sql2008 数据库 tg4msql 必须存在inittg4msql的配置内容如下透明网关主机上的listener.ora的配置内容如下(端口由于1521占用,故采用1522)# listener.ora Network Configuration File: D:appasusoracleproduct10.2.0tg_1netwo
3、rkadminlistener.ora# Generated by Oracle configuration tools.SID_LIST_LISTENER =(SID_LIST =(SID_DESC =(SID_NAME = PLSExtProc)(ORACLE_HOME = D:appasusoracleproduct10.2.0tg_1)(PROGRAM = extproc)(SID_DESC =(SID_NAME = tg4msql)(ORACLE_HOME = D:appasusoracleproduct10.2.0tg_1)(PROGRAM = tg4msql)LISTENER =
4、(DESCRIPTION_LIST =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = asus-PC)(PORT = 1522)(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)重启windows 监听服务,确保透明网关服务启动透明网关主机上的tnsnames.ora的配置内容如下(端口由于1521占用,故采用1522)# tnsnames.ora Network Configuration File: D:appasusoracleproduct10.2.0tg_1networkadmintnsnames.
5、ora# Generated by Oracle configuration tools.EXTPROC_CONNECTION_DATA =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)(CONNECT_DATA =(SID = PLSExtProc)(PRESENTATION = RO)tg4msql=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1522)(CONNECT_DATA =(SERVER
6、 = DEDICATED)(SERVICE_NAME = tg4msql)(HS=OK)下来在A机器上的D:oracleproduct10.2.0db_1networkADMINTNSNAMES.ORA添加tg4msql =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.1.103)(PORT=1522)(CONNECT_DATA =(SID=tg4msql)(HS=OK)测试连通性,此时A机器上的tg4msql 就会被B机器监听侦测解析到。若报无监听错误,请检查B 机器的网关监听服务是否配置正确并正常启动。三、 创建 DBLINK
7、,并测试在 A 机器上通过 PL/SQL 建立 database linkcreate public database link TG4MSQL connect to SA identified by “sa” using tg4msql;tg4msql就是在TNSNAMES.ORA 中的标识。查询DBlink所见里的从sql2008读取数据的表。四、 错误分析1) ORA-02068:以下严重错误源于 TG4MSQLORA-03135:连接失去联系原因:Oracle数据库端的TNSNAMES.ora写法有误,仔细检查是否缺少(HS=OK)或括号是否多余或者有中文括号。正确写法:tg4msql =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST=192.168.1.103)(PORT=1522)(CONNECT_DATA =(SID=tg4msql)(HS=OK)2)SQLSERVER端口确保可以 telnet 192.168.1.103 1433通,否则执行dblink测试不通或一直等待下去(也不报错) ,再无响应。解决:开始-所有程序打开 如下操作重启 即正常telnet 192.168.1.103 1433通过此时再测试执行,结果瞬间出现。