开发者

Too fast response

开发者 https://www.devze.com 2022-12-13 09:54 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消