Too fast response
I have an ASP.NET-MVC application that:
- opens a db transaction
- updates a cart status and other things
- submits this cart to another web server via an HttpRequest
- register in database the transmission with its code status
- send a confirmation mail, th开发者_StackOverflowat the command has been sent
- then if no error has occurs commit the transaction else rollback it.
Normally, after that the distant server sends another web request to my application to a controller action that will update the previous transmission and set an aknowledge field.
My problem is that the distant web server sometimes is very fast and sends the aknowledge status before the transmission insertion in the database is committed, so the update fails. How could I prevent this?
Thanks.
Just make your commit operation in two stages. First is too create record. Then do processing like create mail and so on. And second to make real(logical) commit.
using(var db = new Db(){
db.Insert(
} // This will commit first stage
// Send email do other stuff
using(var db = new Db(){
var t = db.getTransmission()
r.Commited = true;
db.Save();
} // This will logically commit
Can you update the database, commit and mark as inactive or invalid, then take away this mark once you get our acknowledgement status?
I may be misunderstanding what exacty it is you're doing.
精彩评论