views:

110

answers:

2

Hi, I am wondering if there is a best practice in regards to concurrency between asp.net and a windows app using the same db? I have a db with items their quantity, any of these items can be sold with different quantities from a website shopping cart or store location. updating the item quantity when user adds the item to their shopping cart seems to be a problematic approach.

Thanks

A: 

not knowing the business rules regarding how an item can be reserved in a basket (such as basket expiry) can you not maintain 'reserved' and 'sold' counts?

Ok so based on what you say. I'd think perhaps a compensation based system rather than a transaction based system for handling this. Yes you have transactions on sale but thw reserve you don't

Preet Sangha
The database is an SQL 2008 and is setup to be almost identical to NorthWind db, I ended up adding an extra field to the Items table "InSessionCount" which will be a nullable int. when the user "any user" checks out the item, we put the selected quantity in the InSessionCount, if the transaction is approved, we modify the quantity row else we reset the InSessionCount field to null and the order is cancelled.
Sammy
+1  A: 

I would suggest introducing a Gateway into your system. The Gateway would be a single application (or part of one of your existing applications: the winforms app or the web app) that acts as the intermediary to the DB for both the windows app and the web app. This way, you only have one point of failure between db requests and the db itself. Design that Gateway to manage concurrency and then you dont have to worry about other processes writing to your db.

If i was in your position i might select the web app to be the gateway. Create a set of services/repositories to interface with the db and have the UI layer of the web app access those services. Then expose those services via web services (or WCF services) to your windows app for it to access the db instead of it accessing the db directly. This way you have decoupled your system and created a single point of entry to the data store. You'll probably solve a whole lot more problems other than concurrency with this approach.

cottsak