使用场景:当你需要从Oracle数据库上访问另一台SqlServer数据库的数据时,Oracle提供了一个工具:gateways。通过这个工具,你可以创建dblink来连接sqlserver或其他不同公司的数据库----取决于你安装时的选项。
安装GATEWAYS后,使用下列2种方式可创建DBLINK
方式A:
create database link bslink
connect to "username" identified by "password"
using '( DESCRIPTION =
( ADDRESS = ( PROTOCOL = TCP )( HOST = remoteIP )( PORT = 1433 ))
( CONNECT_DATA = (
SID = SQLSERVER数据库名 ) ) ( HS=OK ) ) '
这种方式是不需要配置initdg4msql.ora和tnsnames.
方式B:
1. 在$ORACLE_HOME/dg4msql/admin/initdg4msql ----这步可省略 使用方式A替代
配置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
#
HS_FDS_CONNECT_INFO=[192.168.101.4]//bsdata ----只需要修改这个IP//数据库名
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
2. 配置Oracle主目录下networkadmin目录下的listener.ora。以我的例子,如下:
******************************
# LISTENER.ORA Network Configuration File: C:oracleora92networkadminlistener.ora
# Generated by Oracle configuration tools.
LISTENER = ----此处LISTENER名为LISTENER
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
)
)
)
SID_LIST_LISTENER = -----此处SID_LIST_LINTENER名 同上为LISTENER
(SID_LIST =
(SID_DESC =
(SID_NAME = dg4msql)
(ORACLE_HOME = D:apporacleproduct11.2.0dbhome_1)
(PROGRAM = dg4msql) ----此处PROGRAM对应TNSNAMES中的dg4msql
)
)
3.配置Oracle主目录下networkadmin目录下的tnsnames.ora,以我的例子,如下:
******************************
dg4msql = ---同上对应
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
)
******************************