sqlserver服务器:192.168.6.16 测试数据库:orcl 测试表:shenfen 测试视图:id 端口:1433
oracle服务器:192.168.6.10
gateway安装在192.168.6.16
一、sqlserver 服务器
C:\Users\Administrator>hostname
WIN-MIRBE4NEBAU
C:\Users\Administrator>ipconfig
Windows IP 配置
以太网适配器 本地连接:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::b993:1b16:9593:34d2%11
IPv4 地址 . . . . . . . . . . . . : 192.168.6.16
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.6.1
sqlserver测试数据:orcl数据库下的shenfen表:
二、安装配置gateway
安装步骤略(gateway安装在D:\product\11.2.0\tg_1):
D:\product\11.2.0\tg_1\dg4msql\admin\initdg4msql.ora:
(文件initdg4msql.ora可以直接使用,如若改名init*.ora中的*务必与listener.ora和tnsnames.ora中的SID保持一致)
# This is a customized agent init file that contains the HS parameters
# that are needed for the Database Gateway for Microsoft SQL Server
#
# HS init parameters
#
HS_FDS_CONNECT_INFO=127.0.0.1:1433//orcl --安装gateway过程中科配置sqlserver数据库信息
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
D:\product\11.2.0\tg_1\NETWORK\ADMIN\listener.ora:
# listener.ora Network Configuration File: D:\product\11.2.0\tg_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dg4msql)
---此行务必正确,否则将无法正常使用
(SID_NAME = dg4msql) ---此处的实例名要和上面参数文件(init*.ora)的名字一致
(ORACLE_HOME = D:\product\11.2.0\tg_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = WIN-MIRBE4NEBAU)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = D:\product\11.2.0\tg_1
----------------------------------
如若监听文件中得PROGRAM写错的话,会报错:
SQL> select * from shenfen@test;
select * from shenfen@test
*
ERROR at line 1:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from TEST
----------------------------------
配置listener.ora可以使用gateway安装文件的netmanager图形界面配置:
D:\product\11.2.0\tg_1\NETWORK\ADMIN\tnsnames.ora:
# tnsnames.ora Network Configuration File: D:\product\11.2.0\tg_1\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
dg4msql =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SID = dg4msql)
)
(HS=OK) --此行表示连接的非ORACLE数据库
)
C:\Users\Administrator>lsnrctl status
LSNRCTL for 32-bit Windows: Version 11.2.0.1.0 - Production on 28-4月 -2016 12:5
9:51
Copyright (c) 1991, 2010, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-MIRBE4NEBAU)(PORT=1521)
))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for 32-bit Windows: Version 11.2.0.1.0 - Produ
ction
启动日期 28-4月 -2016 12:51:29
正常运行时间 0 天 0 小时 8 分 21 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 D:\product\11.2.0\tg_1\network\admin\listener.ora
监听程序日志文件 d:\product\11.2.0\tg_1\diag\tnslsnr\WIN-MIRBE4NEBAU\li
stener\alert\log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=WIN-MIRBE4NEBAU)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
服务摘要..
服务 "dg4msql" 包含 1 个实例。
实例 "dg4msql", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
------------------------------------------------------------------------------
附:
使用11.2.0.3.0 32bit版本gateway:
C:\Users\Administrator>lsnrctl status
LSNRCTL for 32-bit Windows: Version 11.2.0.3.0 - Production on 27-4月 -2016 18:21:59
Copyright (c) 1991, 2011, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.6.16)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for 32-bit Windows: Version 11.2.0.3.0 - Produ
ction
启动日期 27-4月 -2016 18:12:47
正常运行时间 0 天 0 小时 9 分 13 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 D:\product\11.2.0\tg_1\network\admin\listener.ora
监听程序日志文件 D:\product\11.2.0\tg_1\diag\tnslsnr\WIN-MIRBE4NEBAU\li
stener\alert\log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.6.16)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
服务摘要..
服务 "dg4msql" 包含 1 个实例。
实例 "dg4msql", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
更换为11.2.0.3.0 64bit gateway版本:
C:\Users\Administrator>lsnrctl status
LSNRCTL for 64-bit Windows: Version 11.2.0.3.0 - Production on 27-4月 -2016 18:37:49
Copyright (c) 1991, 2011, Oracle. All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-MIRBE4NEBAU)(PORT=1521)
))
LISTENER 的 STATUS
------------------------
别名 LISTENER
版本 TNSLSNR for 64-bit Windows: Version 11.2.0.3.0 - Produ
ction
启动日期 27-4月 -2016 18:37:44
正常运行时间 0 天 0 小时 0 分 7 秒
跟踪级别 off
安全性 ON: Local OS Authentication
SNMP OFF
监听程序参数文件 D:\product\11.2.0\tg_1\network\admin\listener.ora
监听程序日志文件 D:\product\11.2.0\tg_1\diag\tnslsnr\WIN-MIRBE4NEBAU\li
stener\alert\log.xml
监听端点概要...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=WIN-MIRBE4NEBAU)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
服务摘要..
服务 "dg4msql" 包含 1 个实例。
实例 "dg4msql", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
命令执行成功
------------------------------------------------------------------------------------
配置完成后建议重新启动SQLSERVER实例及监听地址:(控制面板--管理工具--服务)
三、Oracle服务器
[root@db ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.6.10 db
SQL> !uname -a
Linux db 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
在oracle数据库上创建dblink,连接sqlserver实例:
create database link test connect to sa identified by sa
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.16)(PORT = 1521))
)
(CONNECT_DATA =
(SID = dg4msql)
)
(HS = OK)
)';
四、Oracle服务器上测试如下
1、查询测试表shenfen:
查询视图id: