Tuesday, February 14, 2012

Database Page Counter

Hi All,

I need some comments regarding my Hit Counter that I have created for my sites. Here is my case:

I have developed several websites which I host along with MS SQL server. I created a class that calls a stored procedure to add a count to the database field. The way that I am using it is that every page in the page_load event will call the class indicating which counter to use (i.e. LoginPage, HomePage, ProductPage, etc.). The class in turn will perform the database route to increment the counter. In the Store procedure before incrementing the counter, I first check to see if a record for the current date has been created, if not I add the record with a date stamp with all the different counter values as zero. I then will add 1 to the desired counter for the date.

Is this a good solution?

What I now want to do is create a page that allows the different website owners to access a page with the relevant page counters.

Any ideas will be greatly appreciated.

ThanksIt's hard to offer opinions without seeing the table structure(s) and data.

One of the fields in your table(s) should be something like "CustomerCode". This will enable you to use a WHERE clause to filter the counters appropriate to each customer.

Terri|||I don't think it's a bad way, but what I would do is just create a monthly SQL job to create the records for the next month or so. Currently, you'd only add a record one time per day, but you'd check for its existence perhaps thousands of times throughout the day. Kind of a waste. That way, the record is always there and you're just doing an update for each call rather than a check and then an update.

No comments:

Post a Comment