因业务需求,需要配置oracle访问sqlserver数据
oracle服务器: 192.168.6.10
sqlserver服务器: 192.168.6.16
一、Oracle数据库服务器配置
1、Oracle 数据库服务器信息
[oracle@db ~]$ 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
[oracle@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> select name,dbid,created from v$database;
NAME DBID CREATED
--------- ---------- ---------
ORCL 1435632369 30-MAR-16
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
2、在Oracle服务器上安装gateway(11gR2 gateway是单独的安装包:11.2.0.4.0 x64是第五个安装包)
安装过程默认选择$ORACLE_HOME,安装后在ORACLE_HOME下生成 dg4msql目录
[oracle@db ~]$ cd $ORACLE_HOME
[oracle@db db_1]$ ls
apex clone cv demo has j2ee ldap network opmn owm racg sqldeveloper timingframework xdk
assistants config db_orcl dg4msql hs javavm lib nls oracore patch rdbms sqlj ucp
bin crs db_orcl1 diagnostics ide jdbc log oc4j oraInst.loc perl relnotes sqlplus uix
ccr csmig dbs dv install jdev md odbc ord plsql root.sh srvm usm
cdata css dc_ocm emcli instantclient jdk mesg olap oui precomp scheduler suptools utl
cfgtoollogs ctx deinstall EMStage inventory jlib mgw OPatch owb psu slax sysman wwg
3、在安装界面配置sqlserver数据库相关信息,记录于文件initdg4msql.ora中
[oracle@db db_1]$ cd dg4msql/
[oracle@db dg4msql]$ ls
admin demo driver lib log
[oracle@db dg4msql]$ cd admin/
[oracle@db admin]$ ls
dg4msql_cvw.sql dg4msql_tx.sql initdg4msql.ora listener.ora.sample tnsnames.ora.sample
[oracle@db admin]$ cat initdg4msql.ora
# 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
#本实验环境中sqlserver服务器为192.168.6.16,sqlserver端口为1433,sqlserver中的数据库为orcl
HS_FDS_CONNECT_INFO=[192.168.6.16]:1433//orcl
# alternate connect format is hostname/serverinstance/databasename
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
4、修改$ORACLE_HOME/network/admin下的tnsnames.ora和listener.ora,添加sqlserver实例信息
[oracle@db admin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dg4msql/admin
[oracle@db admin]$ cd ../..
[oracle@db db_1]$ pwd
/u01/app/oracle/product/11.2.0/db_1
[oracle@db db_1]$ cd network/admin/
[oracle@db admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = dg4msql) --此处SID_NAME切勿修改,务必与 initdg4msql.ora中名字保持一致
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(PROGRAM = dg4msql)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@db admin]$ cat tnsnames.ora
#tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
dg4msql =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.10)(PORT = 1521))
)
(CONNECT_DATA =
(SID = dg4msql)
)
(HS=OK)
)
[oracle@db admin]$ tnsping dg4msql
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 27-APR-2016 16:04:58
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.6.10)(PORT = 1521))) (CONNECT_DATA = (SID = dg4msql)) (HS=OK))
OK (10 msec)
5、在Oracle数据库服务器上创建db_link
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)
)';
二、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 1433端口已开通:
telnet 192.168.6.16 1433
如上显示表明已开通。
三:在oracle数据库上测试查看sqlserver orcl数据库的shenfen表