ORACLE 8i的普通連接技術(shù)的介紹
2024-08-29 13:31:11
供稿:網(wǎng)友
oracle 8i的普通連接技術(shù)的介紹
====================================
歡迎大家同我交流:小白 [email protected]
歡迎轉(zhuǎn)載,請(qǐng)保留本聲明,謝謝!
====================================
oracle 8.1.6 中引入普通連接技術(shù)的概念(generic connectivity),這一連接解決方案滿(mǎn)足了對(duì)許多異種數(shù)據(jù)庫(kù)存儲(chǔ)的數(shù)據(jù)訪問(wèn)需求,同時(shí)并不需要安裝oracle的透明網(wǎng)關(guān)(oracle transparent gateway)。該特性允許使用業(yè)界標(biāo)準(zhǔn) odbc 和 oledb 建立透明連接。
什么是普通連接(generic connectivity)
普通連接是oracle的一個(gè)低端數(shù)據(jù)集成解決方案,目標(biāo)是提供oracle 8i可以連接到非oracle數(shù)據(jù)庫(kù)的能力。它的實(shí)現(xiàn),是通過(guò)異種服務(wù)代理(heterogeneous services)來(lái)實(shí)現(xiàn)的。
異種服務(wù)代理的類(lèi)型:
odbc agent for accessing odbc data providersole db agent for accessing ole db data providers that support sql processing--sometimes referred to as ole db (sql)odbc agent for acceng ole db data providers without sql processing support--sometimes referred to as ole db (fs)
普通連接的系統(tǒng)結(jié)構(gòu)圖
oracle客戶(hù)端程序訪問(wèn)非oracle數(shù)據(jù)庫(kù)的過(guò)程:客戶(hù)端程序是通過(guò)sql*net連接oracle服務(wù)器,關(guān)于異種數(shù)據(jù)庫(kù)的訪問(wèn),交給hs代理實(shí)現(xiàn)。
hs代理通過(guò)下面的功能組件實(shí)現(xiàn):odbc管理器->odbc驅(qū)動(dòng)程序->數(shù)據(jù)庫(kù)的網(wǎng)絡(luò)客戶(hù)端->目標(biāo)數(shù)據(jù)庫(kù)。
如果異種庫(kù)和oracle數(shù)據(jù)庫(kù)位于同一臺(tái)服務(wù)器上,一般來(lái)說(shuō)驅(qū)動(dòng)程序是可以直接和本機(jī)的數(shù)據(jù)庫(kù)通訊,就可以省去數(shù)據(jù)庫(kù)的網(wǎng)絡(luò)客戶(hù)端這一層。
數(shù)據(jù)類(lèi)型的轉(zhuǎn)換
oracle自動(dòng)實(shí)現(xiàn)odbc和oledb數(shù)據(jù)類(lèi)型到oracle數(shù)據(jù)類(lèi)型的轉(zhuǎn)換,具體的對(duì)應(yīng)轉(zhuǎn)換可以參考o(jì)racle的聯(lián)機(jī)幫助http://download-west.oracle.com/docs/cd/a87860_01/doc/server.817/a76960/datatype.htm。
普通連接的限制
1 含有blob列的表必須要有一個(gè)主鍵字段;
2 blob/clob數(shù)據(jù)不直接通過(guò)pass-through的查詢(xún)方式;
3 在where子句中包括了函數(shù)的updates或deletes語(yǔ)句不被允許;
4 不支持存儲(chǔ)過(guò)程的調(diào)用;
hs代理(odbc/oledb)不支持分布式事務(wù)(distributed transactions),只支持單點(diǎn)的事務(wù)(single-site transactions)。
普通連接代理的配置
下面,我介紹一下,利用普通連接的odbc配置。利用hs odbc代理連接sql server 2000。
第一步初始化文件的建立
首先,你必須要?jiǎng)?chuàng)建初始化文件。oracle提供了樣例初始化文件,名字是init<agent>.ora,<agent>可能是hsodbc,hsoledb,hsolefs,分別代表了三種類(lèi)型的代理,位于$oracle_home/hs/admin下。
把對(duì)應(yīng)的文件復(fù)制一份出來(lái),并且改名為init<hs_sid>.ora,<hs_sid>是你sql server odbc代理起的別名。
復(fù)制并創(chuàng)建了一個(gè)inithssql2k.ora文件,編輯inithssql2k.ora文件。參數(shù)有:
# 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 = <odbc data_source_name>
#hs_fds_trace_level = <trace_level>
hs_fds_connect_info = sql2k
hs_fds_trace_level = on
hs_autoregister = true
#
# environment variables required for the non-oracle system
#
#set <envvar>=<value>
第二步 創(chuàng)建異種服務(wù)代理的數(shù)據(jù)字典
執(zhí)行$oracle_home/rdbms/admin/caths.sql,創(chuàng)建相關(guān)的系統(tǒng)表和視圖。
第三步 創(chuàng)建異種服務(wù)代理的工作環(huán)境
添加hssql2k的偵聽(tīng)服務(wù),$oracle_home/network/admin/listener.ora
sid_desc=
(sid_name=hssql2k)
(oracle_home=d:/oracle/ora81)
(program=hsodbc)
)
修改$oracle_home/network/admin/tnsnames.ora,添加一個(gè)網(wǎng)絡(luò)服務(wù)名
sql2k,將在后面創(chuàng)建數(shù)據(jù)庫(kù)聯(lián)接時(shí)用到。
sql2k =
(description=
(address=(protocol=tcp)(host=localhost)(port=1521))
(connect_data=(sid=hssql2k))
(hs=ok)
)
重新啟動(dòng)偵聽(tīng),并且察看服務(wù)狀態(tài)
lsnrctl for 32-bit windows: version 8.1.7.0.0 - production on 02-jul-2003 12:49:
30
(c) copyright 1998 oracle corporation. all rights reserved.
welcome to lsnrctl, type "help" for information.
lsnrctl> status
connecting to (description=(address=(protocol=tcp)(host=sam)(port=1521)))
status of the listener
------------------------
alias listener
version tnslsnr for 32-bit windows: version 8.1.7.0.0 - produ
tion
start date 02-jul-2003 11:08:31
uptime 0 days 1 hr. 41 min. 2 sec
trace level off
security off
snmp off
listener parameter file d:/oracle/ora81/network/admin/listener.ora
listener log file d:/oracle/ora81/network/log/listener.log
services summary...
orcl has 1 service handler(s)
orcl has 3 service handler(s)
plsextproc has 1 service handler(s)
hssql2k has 1 service handler(s)
the command completed successfully
lsnrctl>
hssql2k的偵聽(tīng)服務(wù)已經(jīng)正常運(yùn)行了。
第四步 修改數(shù)據(jù)庫(kù)啟動(dòng)參數(shù)文件
修改數(shù)據(jù)庫(kù)啟動(dòng)參數(shù)文件,設(shè)置global_names=false,如果設(shè)置為true(缺省),那么數(shù)據(jù)庫(kù)連接名和全局?jǐn)?shù)據(jù)庫(kù)名一樣,這將會(huì)導(dǎo)致ora-02085的錯(cuò)誤。
第五步 創(chuàng)建訪問(wèn)non-oracle數(shù)據(jù)庫(kù)的連接(database link)
在sqlplus中,執(zhí)行create database link命令。connect to 指定了連接到sql server的用戶(hù)名和密碼。
sql>create public database link sql2k connect to sa identified by manager using ‘sql2k’;
database link created.
第六步 測(cè)試
oracle8i enterprise edition release 8.1.7.0.0 - production
with the partitioning option
jserver release 8.1.7.0.0 - production
sql> connect scott/tiger;
connected.
sql> select count(*) from [email protected];
count(*)
----------
135
現(xiàn)在,oracle已經(jīng)可以訪問(wèn)sqlserver數(shù)據(jù)庫(kù)了。以上都是,筆者參考了oracle的聯(lián)機(jī)幫助,并且實(shí)際測(cè)試的經(jīng)過(guò)。筆者同時(shí)也發(fā)現(xiàn),采用hsodbc其實(shí)也并不是很穩(wěn)定,有的sql語(yǔ)句會(huì)引起hsodb agent的致命錯(cuò)誤,同時(shí)有很多限制,采用透明網(wǎng)關(guān)應(yīng)該就可以獲得很好的效果。
但是, oracle 8i的這個(gè)特性,可以不安裝額外的transparent gateway產(chǎn)品。因此,只要能夠滿(mǎn)足應(yīng)用的數(shù)據(jù)訪問(wèn)要求,采用generic connectivity也不失為一個(gè)快速,經(jīng)濟(jì)的方法。
筆者的測(cè)試環(huán)境:windows2000 server+oracle 8i(8.1.7)