寫了以下的程式做SQL與Oracle的分散式交易:

using (System.Transactions.TransactionScope tx = 
    new System.Transactions.TransactionScope())
{
    //... Update data on SQL Server ...
    using (OracleConnection cn = new OracleConnection(cnStr))
    {
        cn.Open();
        OracleCommand cmdOra = new OracleCommand(
            "INSERT INTO MYLOG VALUES (SYSDATE, 'DEBUG')", cn);
        cmdOra.ExecuteNonQuery();
        cmdOra.CommandText = 
            "SELECT LOGTIME FROM MYLOG WHERE REMARK='DEBUG'";
        OracleDataReader dr = cmdOra.ExecuteReader();
        dr.Read();
        Response.Write(dr["LOGTIME"].ToString());
        dr.Close();
        cn.Close();
    }
    //tx.Complete();
    Response.Write("OK");
}

執行環境為Windows 2008 x64 + ASP.NET 2.0 + System.Data.OracleClient + Oracle 11.1.0.6 x64 Client。程式一直傳回ORA-00161: transaction branch length 105 is illegal (maximum allowed 64) 錯誤。

網路上有不少相關的討論,大都指向Oracle的官方說法:

Windows Vista and Windows Server 2008 introduce new MSDTC changes that do not interoperate with older versions of Oracle Services for MTS. Oracle Services for MTS 10.2.0.4 and higher, with the exception of 11.1.0.6, support these new changes on Windows Vista Service Pack 1 and Windows Server 2008 or higher.

敢情我是中了籤王,10.2.0.4以後版本都可以支援,但11.1.0.6例外。到OTN下載 11107_w2k8_x64_production_client.zip (523MB)。

下載安裝,藥到病除!


Comments

Be the first to post a comment

Post a comment


54 - 22 =