[SQL server] 加入Oracle 作 Linked server

當做系統整合時, 將不同database 接駁是其中一項平常事. SQL server 之間接駁沒啥難度, 然而, SQL server 接駁Oracle卻大有學問, 在這裡, 會示範如何在SQL server 中制作Oracle Link Database.

  1. 先下載及安裝Oracle Client. 於Option 中選擇 Runtime only 便可;
  2. 安裝後開啟SQL Server Management Studio (SSMS), 用sa 權限登入後, 打開Server Objects > Linked Servers > Providers, 確定Oracle Data Provider 已經安裝.
  3. 設定在SQL server 中使用 Provider, 令它可以存取相關的Providor dll files.
    在OraOLEDB.Oracle 中右鍵>Property, ;在 General > Provider Option 中剔取Allow Inprocess
  4. 開始建立Oracle Linked Server.
    在Linked Server 中右鍵, 選取New Linked Server.
  5. 在Oracle 中, 設定如下:
    1. Linked Name: Linked Server 的名字
    2. Provider: Oracle Provide for OLE DB
    3. Product Name: Oracle
    4. Data Source: tnsname 的名字, 可以在%ORACLE_HOME%\client_1\NETWORK\ADMIN\tnsname.ora 中找到.
  6. 選取Security, 選取Be made using this security context, 並在此輸入預設的Credential. 
  7. 執行SQL statement 進行測試, 若有column 傳回表示測試成功.

有時除了table 外, 若要執行Oracle 的 store procedure /package function, 則須要再另外設定如下:

  1. 在安裝Oracle Client 時, 選擇Custom Install 並剔取Oracle Services For Microsoft Transaction Server.
  2. 開啟SQL server 的Component Services, 選取Component Services > Computers > My Computer > Distributed Transaction Coordinator >Local DTC, 右鍵選取Properties
  3. 開啟Security Tag, 剔取Network DTC Access, Allow Remote Client, Allow Inbount 和Allow Outbound 後按OK, 之後會重新啟動MSDTC.

Reference

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.