oracle通過透明閘道器(Oracle Transparent Geteways),訪問ms sql server和其他資料庫

jst143發表於2011-03-16

oracle通過透明閘道器(Oracle Transparent Geteways),訪問ms sql server和其他資料庫

環境:
    1、在安裝有oracle伺服器端,ms sql server的客戶端,通過oracle的透明閘道器訪問ms sql server資料庫
    2、在ms sql server伺服器上建立使用者conn_ora,並且要能訪問ms sql server資料庫msdb

安裝Oracle Transparent Geteways:
    1、'開始'選單的'Oracle Installation Products'下的'Universal Installer'
       \\192.168.0.8\e$\資料工具\oracle9.2\ORANT920\ORA92_1\NT\I386\stage\products.jar
       下一步-
    2、選擇安裝型別:
       自定義,下一步
    3、選擇可用產品元件:
       將 'Oracle Transparent Geteways 9.2.0.1.0'下的'Oracle Transparent Geteways for Microsoft SQL Server 9.2.0.1.0'選中;
       將 'Oracle Transparent Geteways 9.2.0.1.0'下的'Oracle Transparent Geteways for Sybase 9.2.0.1.0'選中;
       下一步;
    4、設定Sybase路徑
       選擇你的'SYBASE的完整安裝路徑';
       下一步
    5、設定資料庫伺服器名 和資料庫名稱???
       Microsoft SQL Server:192.168.0.111
       Microsoft SQL 資料庫:msdb
       伺服器名稱或者ip地址,資料庫名字
    6、繼續安裝:
       \\192.168.0.8\e$\資料工具\oracle9.2\ORANT920\ORA92_2\NT\I386\stage
       \\192.168.0.8\e$\資料工具\oracle9.2\ORANT920\ORA92_3\NT\I386\stage
    7、安裝完成:
       此時,oracle安裝主目錄下有了'tg4msql'目錄
       C:\oracle\ora92\tg4msql

設定環境引數,建立dblink:
    1、C:\oracle\ora92\tg4msql\admin下的inittg4msql.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=ZZL;DATABASE=MSDB"
            HS_FDS_TRACE_LEVEL=OFF
            HS_FDS_RECOVERY_ACCOUNT=RECOVER
            HS_FDS_RECOVERY_PWD=RECOVER
       說明:
           HS_FDS_CONNECT_INFO=ZZL.MSDB和
           HS_FDS_CONNECT_INFO="SERVER=ZZL;DATABASE=MSDB"和
           HS_FDS_CONNECT_INFO="SERVER=192.168.0.111;DATABASE=MSDB"
           都可以,兩種寫法,其中‘SERVER’是伺服器名稱或者ip,DATABASE是資料庫名稱,
           當然,如果在192.168.0.111這臺伺服器上,有兩個sql server例項,則使用‘伺服器名\例項名’的方式設定上面的SERVER值,
           如:HS_FDS_CONNECT_INFO="SERVER=ZZL\MSSQLSERVER;DATABASE=MSDB"

 


    2、設定listener.ora檔案
       位置:C:\oracle\ora92\network\admin
       檔案內容:
                SID_LIST_LISTENER =
                  (SID_LIST =
                    (SID_DESC =
                      (SID_NAME = PLSExtProc)
                      (ORACLE_HOME = C:\oracle\ora92)
                      (PROGRAM = extproc)
                    )
                    (SID_DESC =
                      (GLOBAL_DBNAME = orademo)
                      (PROGRAM = orademo)
                      (ORACLE_HOME = C:\oracle\ora92)
                      (SID_NAME = orademo)
                    )
                    (SID_DESC =
                      (PROGRAM = tg4msql)
                      (ORACLE_HOME = C:\oracle\ora92)
                      (SID_NAME = tg4msql)
                    )
                  )
        其中新增:
            (SID_DESC =
              (PROGRAM = tg4msql)
              (ORACLE_HOME = C:\oracle\ora92)      #oracle的主目錄
              (SID_NAME = tg4msql)
            )

    3、配置tnsnames.ora檔案
       位置:C:\oracle\ora92\network\admin
       檔案內容:
            # TNSNAMES.ORA Network Configuration File: C:\oracle\ora92\network\admin\tnsnames.ora
            # Generated by Oracle configuration tools.
            SDLGDB =
              (DESCRIPTION =
                (ADDRESS_LIST =
                  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.8)(PORT = 1521))
                )
                (CONNECT_DATA =
                  (SID = SSTORA)
                  (SERVER = DEDICATED)
                )
              )
            RADEMO =
              (DESCRIPTION =
                (ADDRESS_LIST =
                  (ADDRESS = (PROTOCOL = TCP)(HOST = zzl)(PORT = 1521))
                )
                (CONNECT_DATA =
                  (SID = orademo)
                  (SERVER = DEDICATED)
                )
              )
            zzl_sql200 =   #資料庫連線名稱,任意命名
              (DESCRIPTION =
                (ADDRESS_LIST =
                  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.111)(PORT = 1521))   #'192.168.0.111'為 oracle伺服器的機器名
                )
                (CONNECT_DATA =
                  (SID = tg4msql)
                )
                (HS=OK)   #Oracle Server要呼叫異構服務來處理
              )
       


        其中新增:
            zzl_sql200 =   #資料庫連線名稱,任意命名
              (DESCRIPTION =
                (ADDRESS_LIST =
                  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.111)(PORT = 1521))   #'192.168.0.111'為 oracle伺服器的機器名
                )
                (CONNECT_DATA =
                  (SID = tg4msql)
                )
                (HS=OK)   #Oracle Server要呼叫異構服務來處理
              )

    4、配置init.ora.1115200612231
       位置:C:\oracle\admin\orademo\pfile
       將global_names設定為真值,及global_names=true

    5、重新啟動服務:
       在window的開始的執行中執行:
       net stop OracleOraHome92TNSListener
       net stop OracleServiceORADEMO
       net start OracleOraHome92TNSListener
       net start OracleServiceORADEMO
      
       說明:OracleOraHome92TNSListener 是監聽服務,OracleServiceORADEMO是例項服務
                 
    6、建立dblink:
       以普通使用者登入oracle:如cs/cs@orademo
      
       --drop DATABASE LINK link_zhaozhenlong;
       CREATE  DATABASE LINK link_zhaozhenlong CONNECT TO "sa" IDENTIFIED BY "xxb" USING 'zzl_sql200';
      
       說明:ms sql server的使用者名稱和密碼必須小寫,而且要加雙引號,
       否則會報如下錯誤:
              錯誤資訊:
                    ORA-28500: connection from ORACLE to a non-Oracle system returned this messsage:
                    [Transparent gateway from MSSQL][Microsoft][ODBC SQL Server Driver][SQL Server]??
                    'sa'????? (SQL State:28000; SQL Code: 18456)
                    ORA-02063: preceding 2 lines from LINK_ZZL
              錯誤原因:
                    在CREATE  DATABASE LINK LINK_ZZL的連線字串中,ms sql server的使用者名稱和密碼必須小寫,而且要加雙引號

     7、在pl/sql中執行:
        select * from sysobjects@link_zhaozhenlong where rownum <=5;
        結果如下:
            1    sysrowsetcolumns    4    S  4   0   0   0   0   0   2005-10-14 1:36:15
            2    sysrowsets               5    S  4   0   0   0   0   0   2005-10-14 1:36:15
            3    sysallocunits            7    S  4   0   0   0   0   0   2005-10-14 1:36:15
            4    sysfiles1                   8    S  4   0   0   0   0   0   2003-4-8 9:13:38
            5    syshobtcolumns      13   S  4   0   0   0   0   0   2005-10-14 1:36:15
       
        訪問dblink時說明:
            這是基於閘道器的方式,因此不能在斷開網路的情況下本地的oracle連線本地的ms sql server
            否則會報如下錯誤:
            ORA-28545: error diagnosed by Net8 when connecting to an agent
            NCRO: Failed to make RSLV connection
            ORA-02063: preceding 2 lines from LINK_ZZL

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23577591/viewspace-689555/,如需轉載,請註明出處,否則將追究法律責任。

相關文章