從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<SID>.ora。例如,我用的SID是MSSQL,那麼我的檔案名稱是initMSSQL.ora。
2. 配置init<SID>.ora,以我的例子,如下:
******************************
# 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 salesdata1@test1;
7.串連成功。其中,connect to後面是使用者名稱,identified by後面是密碼,using後面是SID。
(b)通過hsodbc串連:
1. 在ODBC中建立SQL Server串連的System DSN,我用名字BIO549。(步驟不詳述,請查MSDN)
2. 在Oracle主目錄下hs\admin的目錄下,拷貝inithsodbc.ora並改名為init<SID>.ora。這次,我用的SID是BIO549,所以檔案名稱是BIO549。以我的例子,如下:
*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 <envvar>=<value>
******************************
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:
http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76960/hs_admin.htm
ORA-24289 - ORA-29249:
http://www.stanford.edu/dept/itss/docs/oracle/9i/server.920/a96525/e24280.htm
Making a Connection from Oracle to SQL Server(in English):
http://www.databasejournal.com/features/oracle/article.php/10893_3442661_1