Jump to content

Locking tables


jrich7970

Recommended Posts

Perhaps I'm reading about locks incorrectly, because it looks like they are at a record level. I'd like to lock a table for a time, then unlock it.My situation is that I'm doing a directory list, with files that are strictly named with a date in them. I would like to present them to the user in chronological order (no guarantee that the timestamp on them is correct).So, I'm reading them, extracting the date from the file name, and putting them into a table. Then I'll do a select, ordering by the date.Instead of just dropping the table, I'm just doing a delete * from mytable...Deal is, if TWO people are doing this at the same time, things could get messed up.How do I lock user 2 (or 3, etc) out, until user 1 is complete? Also, can I have user 2 wait until user 1 is complete, or do I just have user 2 error out? Would I set a nice long timeout?Thanks for your help.Oh, sorry, I'm using ASP and an MS Access database.

Link to comment
Share on other sites

You might be able to set locking options in the connection string for the database, but that's probably not going to solve a race condition. You might want to do that manually where you just keep track of which user is currently using the database, and make sure they release the lock when they're finished. The other user could see a page that says it's currently in use, and you could have the page refresh every few seconds or so to check again. Another option is to include a user column in the table, so that each user only works with their own data. Then you wouldn't need to lock anything.

Link to comment
Share on other sites

Another option is to include a user column in the table, so that each user only works with their own data. Then you wouldn't need to lock anything.
Actually, that's an interesting idea! Any way for me to get some unique number that I can use for an ID? I do not require a login...so I can't use any type of a user ID.Is there some session variable that will give me something unique?
Link to comment
Share on other sites

You can probably get a session ID somewhere, or you can generate a unique ID and store it in the session. Unless you're building an intranet application, you can probably also just use the user's IP address.
IP address will be fine. Anything unique (although it will be hard for me to test, since I'll be coming from the same ip!). This is just some silly little "club" website.Thanks
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...