分类: Oracle
2009-08-11 08:53:57
从Oracle 9i连接SQL Server2000,需要用透明网关(Transparent Gateway),通过它,我们可以 sqlplus 操纵其他数据库,如 ms sqlserver 、 sybase 、 infomix 等,实现数据库的异构服务。
在Oracle 8i中没有透明网关,9i自带,但是默认不安装。
(一)安装Transparent Gateway for Windows SQL Server:
*如果在Oracle主目录下有tg4msql文件夹,那么不需要重新安装。
1. 启动Oracle安装盘disk 5里面的setup.exe。
2. 按Next两次,选择Oracle 9i Database 9.2.0.1.0,按Next。
3. 选择Custom,按Next。
4. 按Oracle Transparent Gateway 9.2.0.1.0旁边的"+",选择Oracle Transparent Gateway for Microsoft SQL Server 9.2.0.1.0,按Next。
5. 接着安装。
6. 安装完毕之后,在Oracle主目录下,会有tg4msql文件夹。
(二)配置:
我的环境:
Oracle 服务器:
OS: Windows XP (SP2)
IP: 192.168.1.180
PORT: 1521
SQL 服务器:
OS: Windows 2000
IP: 192.168.1.213
Database Server Name: BIO549
Database Name: salesdata1
(a)通过tg4msql连接:
1. 在Oracle主目录下tg4msql\admin目录下,拷贝inittg4msql.ora并改名为init
2. 配置init
******************************
# This is a sample agent init file that contains the HS parameters that are
# needed for the Transparent Gateway for SQL Server
#
# HS init parameters
#
HS_FDS_CONNECT_INFO="SERVER=BIO549;DATABASE=salesdata1"
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
******************************
3. 配置Oracle主目录下network\admin目录下的listener.ora。以我的例子,如下:
*NEWLISTENER是我新建的LISTENER的名字,默认应该是LISTENER
******************************
# LISTENER.ORA Network Configuration File: C:\oracle\ora92\network\admin\listener.ora
# Generated by Oracle configuration tools.
NEWLISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
)
)
)
SID_LIST_NEWLISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME = MSSQL)
(PROGRAM = tg4msql)
)
)
******************************
4.配置Oracle主目录下network\admin目录下的tnsnames.ora,以我的例子,如下:
******************************
MSSQL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
(CONNECT_DATA = (SID = MSSQL))
(HS=MSSQL)
)
******************************
5. 重起listener。
6. 用sqlplus建立并测试Database Link。在命令行中,用以下命令:
sqlplus /nolog
conn sys/webpos as sysdba ---->用sysdba的身份登陆
alter system set global_names = true; ---->设置global_names=false不要求建立的数据库链接和目的数据库的全局名称一致
create database link test1 connect to sa identified by sa using 'mssql';
select * from ;
7.连接成功。其中,connect to后面是用户名,identified by后面是密码,using后面是SID。
(b)通过hsodbc连接:
1. 在ODBC中建立SQL Server连接的System DSN,我用名字BIO549。(步骤不详述,请查MSDN)
2. 在Oracle主目录下hs\admin的目录下,拷贝inithsodbc.ora并改名为init
*HS_FDS_CONNECT_INFO后面是数据源名称。
******************************
# This is a sample agent init file that contains the HS parameters that are
# needed for an ODBC Agent.
#
# HS init parameters
#
HS_FDS_CONNECT_INFO = BIO549
HS_FDS_TRACE_LEVEL = OFF
#
# Environment variables required for the non-Oracle system
#
#set
******************************
3. 配置listener.ora,这次加入下面一段:
******************************
(SID_DESC=
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME=BIO549)
(PROGRAM=hsodbc)
)
******************************
因此,我的listener.ora全部如下:
******************************
# LISTENER.ORA Network Configuration File: C:\oracle\ora92\network\admin\listener.ora
# Generated by Oracle configuration tools.
NEWLISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
)
)
)
SID_LIST_NEWLISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME = MSSQL)
(PROGRAM = tg4msql)
)
(SID_DESC=
(ORACLE_HOME = C:\oracle\ora92)
(SID_NAME=BIO549)
(PROGRAM=hsodbc)
)
)
******************************
4. 配置tnsnames.ora,如下:
******************************
BIO549 =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.180)(PORT=1521))
(CONNECT_DATA= (SID=BIO549))
(HS=OK)
)
******************************
5. 重起listener并建立连接。
(三) 注意:
我在测试的时候,起先总是有ORA-28545的错误,经调查含义如下:
ORA-28545 error diagnosed by Net8 when connecting to an agent
Cause: An attempt to call an external procedure or to issue SQL to a non-Oracle system on a Heterogeneous Services database link failed at connection initialization. The error diagnosed by Net8 NCR software is reported separately.
Action: Refer to the Net8 NCRO error message. If this isn't clear, check connection administrative setup in tnsnames.ora and listener.ora for the service associated with the Heterogeneous Services database link being used, or with 'extproc_connection_data' for an external procedure call.
我仔细的查看了所有文件的配置,发现是由于listener的名字导致的错误(SID_LIST_NEWLISTENER),因此我建议,如果出现这个错误,请仔细检查所有的配置文件。
(四)推荐阅读:
Managing Oracle Heterogeneous Services Using Transparent Gateways:
ORA-24289 - ORA-29249:
Making a Connection from Oracle to SQL Server(in English):