I have this code:
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;
}
The AddAck method will save that string to the database (Using Entity Framework).
When I run this without the last statement throw, it saves my error message to database fine.
When I have the throw; in there, it says it saves but when I query the database it is not in there. I can even run a entity query via my data context right after saving (in the code) and it returns the value as if it is saved (though that may be using a cached version). But if I go and query afterwards the data is not there….
I have checked to be sure that no other logic is causing the value to be removed on an exception.
Any ideas what could be causing this?
OK, post as an answer here, it comes in my mind very easily as I used to met the same issue, and figured out it was just caused I didn’t commit the DB transaction.
Thanks, 🙂