Issue I had while caching a Dataset in ASP.Net

Today I had a bug where pricing on my application was changing every time you clicked the button to search for product.  After running it through the debugger, I discovered that the cached Dataset was retaining the mark ups every time they were applied.  Here is a detail of what was happening:

When the user made a request for product I was going out to get the product based on their user settings (Who the were, what mark up was defined for their company, what market do the do business in, etc.)  These are generic settings that will not change during the session so i was caching this Dataset to alleviate going back to the DB every time.

Next, they would refine there search by the product criteria.  At this point I would get the Dataset out of cache, filter based on the criteria they chose and apply the mark up to the values in the Dataset.

Well, the caching holds a reference to the Dataset so any changes I made to the price in the Dataset was reflected in the cache.  So, if the user performed a search that returned any of those same products, the mark up was applied to the price in the Dataset, which had already been marked up.  So, depending on how many time they searched for the same product, that product got marked up that many times.  Big problem!

To alleviate this I simply copied the Dataset into a new one before I did my mark up.  That way the mark up was never reflected in the cached Dataset.  So the next time that data was received from the cache it still had it’s original price.  Very tricky to spot.  I’m glad it’s over.

ASP.Net Web Deployment Projects

I just ran across a great blog entry that explains the Web Deployment Project for ASP.Net.

Scott Guthrie's Web Deployment Blog Entry 

Scott does a great job of detailing how to create these and get them working.  Make sure you read the final portion about creating an MSI based on the output from the Web Deployment Project.  Having an MSI would please most of the system admins out there that are in charge of deployment…

Here is a word document that also does a great job of explaining the Web Deployment Projects

Web Deployment Projects Doc

Thanks FDC!

I’d like to say thank you to FDC for having me for the Events and Structural Design Patterns presentation.  Please feel free to email me your questions or comments or just post a comment to this blog entry.  I’d love to here how the drills are going.  I’d also like any feed back you can give on the presentations and how to make them better.

I will also be doing the presentation on Oct. 9th.  The topic will be Behavioral Design Patterns.