【茶包射手日記】Oracle Client版本與分散式交易

接獲報案,同事欲將測試網站移至新主機,遇到Oracle無法進行分散式交易的情況,得到以下錯誤訊息:

    Oracle.DataAccess.Client.OracleException
    Unable to enlist in a distributed transaction /無法列於分散式交易中

該網站尚有其他SQL分散式交易正常,單獨連線Oracle不參與分散式交易也正常,主機Oracle Client版本為ODAC121024(12.1.0.2),並確認已安裝Oracle Services for Microsoft Transaction Server。

先寫一小段程式進行對照,建立TransactionScope包入SQL及Oracle查詢,通過測試:

 using (TransactionScope tx = new TransactionScope()) 
{
    using (var cnSql = new SqlConnection("data source=SqlSvAr;user id=someone;password=****")) 
    {
        cnSql.Open();
        var cmd = cnSql.CreateCommand();
        cmd.CommandText = "select getdate()";
        var dr = cmd.ExecuteReader();
        dr.Read();
        Console.WriteLine(dr[0]);
    }
    using (var cnOra = new OracleConnection("data source=OraSvrA;user id=someone;password=****"))
    {
        cnOra.Open();
        var cmd = cnOra.CreateCommand();
        cmd.CommandText = "select sysdate from dual";
        var dr = cmd.ExecuteReader();
        dr.Read();
        Console.WriteLine(dr[0]);
    }
    tx.Complete();
}

由此可確認該主機可支援Oralce分散式交易。下一步請同事修改測試範例,逐一換成問題程式所用的連線或物件,觀察到一個現象:將測試程式所連線的Oracle Server由OraSvrA換成OraSvrB,就會重現無法參與分散式分易錯誤。

比對後發現兩台Oracle Server版本不同,OraSvrA為11.2.0.2.0,有問題的OraSvrB為10.2.0.4.0,推測可能是新版Oracle Client 12.1.0.2搭配舊版Oracle Server之相容問題,依此方向爬文,找到一篇Oracle論壇討論提到極度類似狀況,依網友測試結果,問題出現在Oracle 12新版Client連線10.2.0.3及10.2.0.4等舊版Oracle Server,升級到10.2.0.5可解決:

…My team has been able to reproduce this problem with DB 10.2.0.3, but not with DB 10.2.0.5. If it's possible, I would recommend using 10.2.0.5 if you need an immediate solution. …

… the same issue to me in Oracle 10. @10.2.4. …

至此得到結論,OraSvrB為10.2.0.4,符合論壇所說的出錯情境。

不想糾結於舊版要不要升級,決定花時間將OraSvrB上的資料庫搬至OraSvrA,問題消失,收工!

歡迎推文分享:
Published 05 May 2016 09:26 PM 由 Jeffrey
Filed under:
Views: 44,854



意見

# Phoenix said on 07 May, 2016 01:10 AM

看起來怪怪的,分散式交易commit的時候,connection已經解構,正常來說,connection不是應該等到commit後才解構

# Jeffrey said on 07 May, 2016 06:31 AM

to Phoenix, 「不用刻意調整Connection配合交易」也是TransactionScope神奇之處。請參考:https://goo.gl/O4ZvIu

Transactions started through System.Transactions are controlled through the System.Transactions infrastructure, and are not affected by SqlConnection.Close.

你的看法呢?

(必要的) 
(必要的) 
(選擇性的)
(必要的) 
(提醒: 因快取機制,您的留言幾分鐘後才會顯示在網站,請耐心稍候)

5 + 3 =

搜尋

Go

<May 2016>
SunMonTueWedThuFriSat
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
 
RSS
創用 CC 授權條款
【廣告】
twMVC
最新回應

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


Syndication