SQL SERVER CONCURRENCY PROBLEM

  • SQL SERVER CONCURRENCY PROBLEM:

    In my application (its a online booking application) if two user are viewing the availibility for tickets and there are 3 tickets available if first user update for 3 tickets and he get the confirmation after that another user who is still viewing 3 tickets are available, and try to update book for 3 tickets.

    Problem comes here. In the database first it will book tickets for first user and after that it will updates for second user. Tickets booked by first user will updates with tickes booked by second user.

    It should be there for first user but it is updating for second user.

    Plz Help how to resolvethis problem.

  • Sounds like there is a problem with your code.  Looks like you need to check PRIOR to updating ANYTHING that you need to ensure that the tickets have not already been taken....



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Does your booking process go over several screens?  My local theatres have a system where you can pre-order your tickets over the net and even choose the seats you want to sit in.  Trouble is, their credit card details collection goes over a couple of screens, so I think they place a flag against the seat in the database that lasts for 20 mins or so.  Whilst that flag is there, no other user can attempt to even book that seat.  If I decide not to book and close my browser, the seat is still "held" for 20mins but at least it gets rid of the concurrency issue somewhat in that situation.

    As AJ said, you will need to not trust the state informaton that you served up on your webpage (such as which seats are available) - you can't trust anything you receive via a web browser as a "clever" user could always have their own little custom app sending you web requests, bypassing anything that you thought the browser's javascript capabilities, hidden form fields, etc were achieving for you.  If you sent the user a page saying X seats are available and the user tries to buy X seats, double check in your server code that X are still available - do it in a transaction with a HOLDLOCK on your select statement so that the subsequent update (in the same transaction) will be updating rows that no one else could have updated...

    Sorry for long response - hope some of it makes sense!  Cheers  

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply