By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,172 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,172 IT Pros & Developers. It's quick & easy.

database access

P: n/a
dee
Hi
I just implemented a hit counter. I lookup the value from an access database
table and then increment and update the result to databse. What happens if
two users access this code at the same time? Is there locking in aspnet?
Thanks.
Dee
Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"dee" <de*@home.net> wrote in news:OE*************@TK2MSFTNGP10.phx.gbl:
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse.
What happens if two users access this code at the same time? Is there
locking in aspnet?


That's upto you to implement... you could lock the row in the database.

Or why don't you just insert a record for each access - and do a SELECT
COUNT to find out the number of hits? While it'll take up more space in the
database, it's definately safer than incrementing a value.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2

P: n/a
dee
Thanks Lucas
I hadn't thought of that its an interesting idea.
Would you have the same approach when database is accessed to change a
user's password, i.e., create a new row with the new password and delete the
old entry?
Dee
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"dee" <de*@home.net> wrote in news:OE*************@TK2MSFTNGP10.phx.gbl:
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse.
What happens if two users access this code at the same time? Is there
locking in aspnet?


That's upto you to implement... you could lock the row in the database.

Or why don't you just insert a record for each access - and do a SELECT
COUNT to find out the number of hits? While it'll take up more space in
the
database, it's definately safer than incrementing a value.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #3

P: n/a
dee
Thanks Lucas
Would INSERTs need to be synchronized too?

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"dee" <de*@home.net> wrote in news:OE*************@TK2MSFTNGP10.phx.gbl:
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse.
What happens if two users access this code at the same time? Is there
locking in aspnet?


That's upto you to implement... you could lock the row in the database.

Or why don't you just insert a record for each access - and do a SELECT
COUNT to find out the number of hits? While it'll take up more space in
the
database, it's definately safer than incrementing a value.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #4

P: n/a
"dee" <de*@home.net> wrote in news:Ow*************@TK2MSFTNGP11.phx.gbl:
Thanks Lucas
I hadn't thought of that its an interesting idea.
Would you have the same approach when database is accessed to change a
user's password, i.e., create a new row with the new password and
delete the old entry?


No, I would just update the user's password record. This is because when
you update a password record, you are updating a specific record for a
specific user. While it is possible that 2 different people may update the
same password record, this is a rare occurance.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #5

P: n/a
You should put this in a transaction. That way, as soon as one user has
updated the total the row in whatever table keeping that total will become
locked. The second user's thread will wait until the first user's
transaction has finished before it will proceed.

The other way, is to synchronize access to the block of code updating the
hit counter by using Monitor.Enter/Monitor.Exit. I think there is also a
Lock statement that lets you lock on an object.

"dee" <de*@home.net> wrote in message
news:OE*************@TK2MSFTNGP10.phx.gbl...
Hi
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse. What
happens if two users access this code at the same time? Is there locking
in aspnet?
Thanks.
Dee

Nov 19 '05 #6

P: n/a
dee
Thanks alot.
That's very helpful.

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"dee" <de*@home.net> wrote in news:Ow*************@TK2MSFTNGP11.phx.gbl:
Thanks Lucas
I hadn't thought of that its an interesting idea.
Would you have the same approach when database is accessed to change a
user's password, i.e., create a new row with the new password and
delete the old entry?


No, I would just update the user's password record. This is because when
you update a password record, you are updating a specific record for a
specific user. While it is possible that 2 different people may update the
same password record, this is a rare occurance.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #7

P: n/a
dee
Marina
Thanks for your suggestion.
Appreciative your help.
Dee
"Marina" <so*****@nospam.com> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
You should put this in a transaction. That way, as soon as one user has
updated the total the row in whatever table keeping that total will become
locked. The second user's thread will wait until the first user's
transaction has finished before it will proceed.

The other way, is to synchronize access to the block of code updating the
hit counter by using Monitor.Enter/Monitor.Exit. I think there is also a
Lock statement that lets you lock on an object.

"dee" <de*@home.net> wrote in message
news:OE*************@TK2MSFTNGP10.phx.gbl...
Hi
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse. What
happens if two users access this code at the same time? Is there locking
in aspnet?
Thanks.
Dee


Nov 19 '05 #8

P: n/a


this newsgroup is a joy to behold

that was one of the sweetest exchanges i have ever seen

get a room!

and why not read to each other from a book about database locking?

oh and make sure to buy a big hard disk to store all those hitcounter
records, they will make great reading:

1 hit
2 hit
3 hit
4 hit
5 hit
6 hit
....
12,234,154 hit
12,234,155 hit

ha ha ha ha ha

brilliant

you guys are the best

oh no! what happens if the hit counter is updated after the first
user comes but before the first user receives the html?
he will see a number out by one!!!! thats deception!!!!
maybe we can implement a distributed transaction coordinator
to make sure that the users eyes have processed the information
and their brain has fully understood it before updating the hit
counter and releasing a page to another user
oh no! what if google spiders the page???? should we include
that in the count??? maybe just half a hit? or should we make
a new table to keep track of googles hits??? maybe we should ring
google now and ask ... but we want to track whether the user
is male or female, lets ask them to fill in their telephone number
so we can ring and ask!! maybe we can just dial their ip address ...
i'm sure it will work





dee wrote:
Marina
Thanks for your suggestion.
Appreciative your help.
Dee
"Marina" <so*****@nospam.com> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
You should put this in a transaction. That way, as soon as one user has
updated the total the row in whatever table keeping that total will become
locked. The second user's thread will wait until the first user's
transaction has finished before it will proceed.

The other way, is to synchronize access to the block of code updating the
hit counter by using Monitor.Enter/Monitor.Exit. I think there is also a
Lock statement that lets you lock on an object.

"dee" <de*@home.net> wrote in message
news:OE*************@TK2MSFTNGP10.phx.gbl...
Hi
I just implemented a hit counter. I lookup the value from an access
database table and then increment and update the result to databse. What
happens if two users access this code at the same time? Is there locking
in aspnet?
Thanks.
Dee



Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.