How can I have my application notify me of someone is looking at the same record in the database

Please help
  I am updating an asp.net c# application to tell me when someone has the same application open on a different browser and looking at the same record I am. I need for it to say " Record open by username" or something to that aspect
vcurtisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
Simple answer is not possible.
0
vcurtisAuthor Commented:
can you psedo code it, or do you have a reference or sample code
0
Russ SuterCommented:
It is possible. I've done it with webforms but not with MVC (yet).

You'd need to write additional code to manage session state in such a way that some session data is registered in a global variable which is accessible by all active sessions. For example, whenever a user accesses a record in a database you can store the Id of that record in a global array. You can then have each session query the array to find out if the item is already in the array. If it is, someone else is using it.

You do need to be careful though to make sure that you manage the array correctly which means inserting the element when the record is being accessed but more importantly removing it when the resource is freed. This can become an issue if the user just closes the browser window because the server has no way of knowing that the client is no longer there. The Session_End method in global.asax can help you with that but then you'll have a locked record on an abandoned session until the session finally times out.

A more responsive approach might be to have the client check in periodically using an Ajax call. If it misses, say, 3 consecutive check-in intervals you can assume the session has been abandoned.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Carl TawnSystems and Integration DeveloperCommented:
I've seen this sort of thing before in scenarios when another user has the record open for editing, but not just for viewing. The difficulty with web applications for this sort of thing is knowing when the user has finished looking at a record.

Is it actually viewing the record you want to know about, or is it just if somebody is actively editing it?
0
vcurtisAuthor Commented:
Thank you for your comments.

additional information
1) I want to know when someone is looking at the record, therefore blocking them from editing
2) I am using webforms. so if anyone has any sample code or examples. I would grately appreciate it
0
David Johnson, CD, MVPOwnerCommented:
webforms are stateless.  just because a record is visible and even if you start to edit it and then disconnect  there is no way of if you locked the record to unlock the record.
0
dejaanbuCommented:
will this idea work?

have a flag column in your table which is set it to true when any user opens it. and after saving/cancelling the record, the flag should set back to false. Or else you can have userid (who is viewing currently) as a new column in your table and set it to zero when editing/cancelling finished.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcurtisAuthor Commented:
Awesome answes, Thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.