我有這樣的代碼:重新拋出異常導致我的數據不保存
catch (Exception e)
{
try
{
transmitModel.AddAck(transmitBatchId,
"<error><message>" + e.Message + "</message><stack>" + e.StackTrace +
"</stack><Location>FromLisAtOMServer<Location>" +
"<TransmitBatchId>" + message.TransmitBatchId +
"</TransmitBatchId></error>", false, true);
}
// If we fail to log, we don't want that to bubble up...
// We want the real error to do that.
catch (Exception){}
// Re-throw the exception so that the service bus will
// move this off to the error queue.);
throw;
}
的AddAck方法將保存該字符串到數據庫(使用實體框架)。
當我運行這個沒有最後一條語句throw
,它將我的錯誤消息保存到數據庫罰款。
當我有throw;
在那裏,它說它保存,但是當我查詢數據庫它不在那裏。我甚至可以在保存之後(在代碼中)通過我的數據上下文運行一個實體查詢,並且它返回值就好像它被保存了一樣(儘管這可能是使用緩存版本)。但是,如果我去後查詢數據是不存在的......
我已檢查以確保沒有其他邏輯導致值在異常時被刪除。
任何想法可能導致這種情況?
聽起來像你沒有提交數據庫交易? – 2012-03-15 15:22:38
但是,提交日誌到db的代碼在哪裏呢? – Tigran 2012-03-15 15:26:48
這個事務不是通過finally語句的某個地方回滾了嗎? – 2012-03-15 15:26:51