oracle 11g建立DBLink访问sql server数据库

时间:2021-02-19 20:23:14

1.安装oracle数据库(步骤省略)

           (IP:172.29.29.36)安装路径:E:\oracle\product\11.2.0\dbhome_1

2.安装oracle gateways透明网关(安装步骤省略)

           (IP:172.29.29.36)安装路径:E:\oracle\product\11.2.0\dbhome_1

             注:oracle gateways的安装路径应与oracle的路径一致,据说可以不装在一起,但是本人测试发现后续访问的时候有报错,具体原因木有找出来,但是装在同一个目录,经      过测试是可行的~~

3.sql server安装服务器地址:172.29.29.39

4.配置

(1)E:\oracle\product\11.2.0\dbhome_1\dg4msql\admin目录下:

           initdg4msql.ora文件内容

HS_FDS_CONNECT_INFO=172.29.29.39:1433//AstCTI #安装sql server的ip地址,默认的端口,数据库名
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER

           listener.ora.sample文件内容

LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=dg4msql)
(ORACLE_HOME=E:\oracle\product\11.2.0\dbhome_1)
(PROGRAM=dg4msql)
)
)

#CONNECT_TIMEOUT_LISTENER = 0

            tnsnames.ora.sample文件内容

dg4msql  =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
)


(2)E:\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN目录下:

                 tnsnames.ora文件内容

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

dg4msql =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=172.29.29.36)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
)
             listener.ora文件内容:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=dg4msql)
(ORACLE_HOME=E:\oracle\product\11.2.0\dbhome_1)
(PROGRAM=dg4msql)
)
)
ADR_BASE_LISTENER = E:\oracle

5.建立DBLINK

-- Drop existing database link 
drop database link DBTEST1;
-- Create database link
create database link DBTEST1
connect to SA identified by "123456" --sa 123456分别是sql server数据库的用户名密码
using 'dg4msql';

6.连接访问:select * from cti_agent_status_record@dbtest1 order by "begin_time" desc;

ps:如果习惯使用pl/sql的宝宝们,在你们的pl/sql的“工具”——“首选项”中配置了oracle主目录名,则要把该配置下的listener.ora和tnsnames.ora文件换成跟E:\oracle\product\11.2.0\dbhome_1\NETWORK\ADMIN目录下的这两个文件的内容。