var transStatus = SpringHelper.InitTransactionManagr(); //取得 Spring.NET 的 TransactionStatustry{
using (SpringHelper.GetScope())
{
var adoTxObj = transStatus.Transaction as AdoTransactionObjectSupport;
var connHolder = adoTxObj.ConnectionHolder;
//先檢查是否已建立 LocalDataStoreSlot ldsTx = System.Threading.Thread.GetNamedDataSlot("springTx");
//將 DbTransaction 放到 Thread Local Storage 之中 System.Threading.Thread.SetData(ldsTx, connectionHolder.Transaction);
// ... 新、舊交雜在一起使用 ...
//最後沒問題就 Commit SpringHelper.Tx.Commit(transStatus);
}
}
catch (Exception ex)
{
//有錯誤就 Rollback SpringHelper.Tx.Rollback(transStatus);
}
var ldsTx = System.Threading.Thread.GetNamedDataSlot("springTx");
var tx = Thread.GetData(ldsTx) as SqlTransaction;
if (tx != null)
command.Transaction = tx;