[英].Net SAP Transaction restart from client
我正在使用.Net NCo 3.0 庫並嘗試了一個 tRFC 示例,其中我看到創建了事務 ID 並與 RFC function 相關聯,然后調用,在成功事務后,事務 ID 被刪除,這里我們維護事務每個tRFC操作在數據庫中的詳細信息,所以,在這種情況下,如果事務失敗,我們可以從數據庫中獲取ID,我們可以重試,我想知道重試機制的代碼實現,有可能SAP 服務器已關閉,因此何時以及如何重新啟動並確保發起的事務只執行一次,不會丟失數據且不會重復。
TidStore tidStore = new TidStore("clientTidStore", false);
static RfcTransaction CreateTransaction(TidStore tidStore, out string data)
{
RfcTransaction trans = new RfcTransaction(); // This creates a fresh TID.;
Console.Write("Please enter some input data: ");
data = Console.ReadLine();
FileStream dataFile = new FileStream(trans.Tid.TID, FileMode.Create, FileAccess.ReadWrite);
byte[] utf8Data = Encoding.UTF8.GetBytes(data);
dataFile.Write(utf8Data, 0, utf8Data.Length);
dataFile.Close();
tidStore.CreateEntry(trans.Tid.TID);
return trans;
}
private void SubmitTransaction(RfcTransaction trans, TidStore tidStore, String data)
{
try
{
IRfcTable dataTable = stfc_write_to_tcpic.GetTable("TCPICDAT");
dataTable.Append();
dataTable.SetValue(0, data);
// Insert the function module into the transaction:
trans.AddFunction(stfc_write_to_tcpic);
stfc_write_to_tcpic = (IRfcFunction)stfc_write_to_tcpic.Clone();
dataTable = stfc_write_to_tcpic.GetTable("TCPICDAT");
dataTable.SetValue(0, data + " -- data of the second function module");
trans.AddFunction(stfc_write_to_tcpic);
trans.Commit(_ECCsystem);
tidStore.SetStatus(trans.Tid.TID, TidStatus.Committed, null);
File.Delete(trans.Tid.TID);
_ECCsystem.ConfirmTransactionID(trans.Tid);
tidStore.DeleteEntry(trans.Tid.TID);
}
catch (Exception e)
{
tidStore.SetStatus(trans.Tid.TID, TidStatus.RolledBack, e.Message);
}
}
}
}
您需要創建自己的 function 並設置一個時間間隔,以檢查哪些 TID 尚未處理。
關於在外部程序端處理和實現 SAP 事務處理,我認為SAP NetWeaver RFC SDK 7.50 Programming Guide中有一些一般性的解釋,這些解釋很有幫助。 請參閱第 4.3、4.4 和 5.5 章。 它比SAP .NET 連接器 3.0 編程指南中的解釋更詳細,並且它也可以輕松地適應 NCo 編程 API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.