views:

76

answers:

2

Hi,

My website has a setup whereby when the application starts a module called SiteContent is "created". This runs a clearup function which basically deletes any irrelevant data from the database, in case any has been left in there from previously run functions.

The module has instances of Manager classes - namely RangeManager, CollectionManager, DesignManager. There are others but I will just use these as an example. Each Manager class contains an array of items - items may be of type Range, Collection or Design, whichever one is relevant. Data for each range is then read into an instance of Range, Collection or Design. I know this is basically duplicating data - not very efficient but its my final year project at the moment so I can always change it to use Linq or something similar later, when I am not pressured by the one month deadline.

I have a form which, on clicking the Save button, saves data by calling SiteContent.RangeManager.Create(vars) or SiteContent.RangeManager.Update(Range As Range, vars) (or the equivalent for other manager classes, whichever one happens to be relevant).

These functions call a stored procedure to insert or update in the relevant table.

Classes Range, Collection and Design all have attributes such as Name, Description, Display and several others. When the Create or Update function is called, the Manager loops through all the other items to check if an item with the same name already exists. The Update function ensures that it does not compare the item being updated to itself. A custom exception (ItemAlreadyExistsException) is thrown if another item with the same name is found.

For some weird reason, if I go into a Range, Collection or Design in edit mode, change something and try to update it, it occasionally doesnt update the item. When I say occasionally I mean every 3 - 4 page loads, sometimes more. I see absolutely no pattern in when or why it occurs. I have a try-catch statement which catches ItemAlreadyExistsException, and outputs "An item with this name already exists" when caught. Occasionally it will output this; other times it will not.

Does anyone have any idea why this could happen? Maybe a mistake which someone has made and solved before?

I used to have regular expressions in place that the names were compared to - I believe it was [a-zA-Z]{1, 100} (between 1 and 100 lower- or upper-case characters). For some reason the customer who I am developing the site for used to get errors saying its not in the correct format. Yet he could try the same text 5 minutes later and it would work fine. I am thinking this could well be the same problem, since both problems occur at random.

Many thanks in advance.

Regards,

Richard Clarke

Edit: After much time spent narrowing down the code, I have decided to wait till my brother, who has been a programmer for at least 8 years more than I have, to come down over Easter and get him to have a look at it. If he cant solve it then I will zip the files up and put them somewhere for people to access and have a go at.

I narrowed it down literally to the minimum number of files possible, and it still occurs. It seems to be about every 10th time. Having said that, I force the manager classes to refresh every 10 page loads or 5 minutes (whichever one is sooner). I may look into this - this could be causing a problem. Basically each Manager contains an array of an object. This array is populated using data from the database. The Update function takes an instance of the item and the new values to be set for the object. If it happens to be a page load where the array is reset (ie the data is loaded freshly from the database) then the object instance with the same ID wont be the same instance as the one being passed in. This explains the fact that it throws an ItemAlreadyExistsException now and then. It all makes sense now the more I think about it. If I were to pass in the ID of the object to be altered, rather than the object itself, then it should work perfectly. I will answer the question if I solve it..

A: 

Woohoo seems I have solved the problem. The refresh sub was being called in the page init event, before (I think) the button click event was being called. Therefore the items of each manager was being recreated/populated. By moving the sub call from init to loadcomplete I managed to solve the problem, it seems.

It still doesnt solve the problem the customer was having with being told he could not put a particular string and then it being successful a while later.. must be a different problem, as the refresh thing was only implemented recently.. but at least one problem appears to be solved.

Thanks for trying to help guys.

Regards,

Richard

ClarkeyBoy
A: 

More information: I have implemented the changes sitewide, found they dont work (maybe I was missing one or two changes or something..) and undone the changes. However I soon realised that the "data refresh" mechanism had been put in place simply because we had live and test as two applications running off the same database at one point, as we wanted to get the website live as soon as possible. After much fiddling since the go-live date I managed to copy all the test data to the live database and swap the live site to use the live database, so there was no need to refresh the data anymore.

Basically because the data was being loaded into instances of classes, they both effectively created their own datasources until the application was recycled. This meant that temporarily they were running independently. There was some functionality in test that wasnt in live and some in live that wasnt in test, so to make several changes to one item which require test-only and live-only functionality you would have to make changes in test, wait till the live application is recycled, then make any required changes in live. This was why I decided to create the 10-page-refresh mechanism - so live would have to be refreshed 10 times at the most for the data to be up to date. Its a bit complex to explain why they were not both roughly the same, but basically test had a fully functional but slightly glitchy admin front end and a buggy customer front end whereas live had all the customer front end bugs fixed and hardly any of the functionality in the admin front end, but the few bits which were there were bug free and there were a few extra bits put in there too. The fact that my laptop was stolen a couple of months ago so, having not backed up the code, I had to decompile the test site and debug the decompiled code before I could advance any further by way of functionality for the live site. The customer wanted to still use the test version for the functionality it had while I attempted to decompile the test DLL and catch up for the live site, but wanted me to prioritise on some of the functionality which was not present in the test site - hence we had to have them both running off the same database. I hope this clears up any confusion anyone may have had in why this is so complicated.

So to sum up, I found a way around the problem by removing the refresh function altogether, and it was caused primarily by having live and test running off the same database but having very different amounts of functionality and very different numbers of glitches. It was basically caused by having to rush to get the site ready for the go-live date whilst catching up having had my laptop stolen and having to decompile the DLL for the test site.

Regards,

Richard

ClarkeyBoy