oracle9i與SQL的連接

經過數據連接(Database Link),從Oracle 9i 鏈接 SQL Server 2000(實例)web

從Oracle 9i鏈接SQL Server2000,須要用透明網關(Transparent Gateway),經過它,咱們能夠 sqlplus 操縱其餘數據庫,如 ms sqlserver 、 sybase 、 infomix 等,實現數據庫的異構服務。sql

在Oracle 8i中沒有透明網關,9i自帶,可是默認不安裝。數據庫

(一)安裝Transparent Gateway for Windows SQL Server:服務器

*若是在Oracle主目錄下有tg4msql文件夾,那麼不須要從新安裝。oracle

1. 啓動Oracle安裝盤disk 5裏面的setup.exe。tcp

2. 按Next兩次,選擇Oracle 9i Database 9.2.0.1.0,按Next。ide

3. 選擇Custom,按Next。sqlserver

4. 按Oracle Transparent Gateway 9.2.0.1.0旁邊的"+",選擇Oracle Transparent Gateway for Microsoft SQL Server 9.2.0.1.0,按Next。測試

5. 接着安裝。ui

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),所以我建議,若是出現這個錯誤,請仔細檢查全部的配置文件。

文章如轉載,請註明轉載自【網管小王的獨立博客】:http://www.5iadmin.com/

相關文章
相關標籤/搜索