473,416 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Determine which user has locked a record

I'm trying to determine which user has locked a given record from VB6.

I know I can use sp_lock and sp_who, and match up the data to determine
which users have locked records in my database, however I haven't seen a way
to match the specific user to the specific record. What am I missing here?

Thanks!

*David*
Jul 23 '05 #1
5 5989
Use the sysprocesses table and check the blocked column. This column
will contain the process id of the process holding the lock. A simple
check for that process should tell you who has the lock.

--
David Rowland
MS SQL Server DBMonitor author
http://dbmonitor.tripod.com

Jul 23 '05 #2
You can get to the table and index level by using the objid and indid.
However, many lock resources are actually hashed values so you'll have
difficulty identifying a specific row.

However, the need to do this sort of thing in application code may be a
larger design issue. Pessimistic locking is bad for both performance and
concurrency. It is best to avoid open transactions when waiting for user
input because users may get interrupted or go to lunch. This can lead to
serious blocking issues.
--
Hope this helps.

Dan Guzman
SQL Server MVP

"David C. Barber" <da***@NOSPAMdbarber.com> wrote in message
news:4e********************@comcast.com...
I'm trying to determine which user has locked a given record from VB6.

I know I can use sp_lock and sp_who, and match up the data to determine
which users have locked records in my database, however I haven't seen a
way
to match the specific user to the specific record. What am I missing
here?

Thanks!

*David*

Jul 23 '05 #3
David C. Barber (da***@NOSPAMdbarber.com) writes:
I'm trying to determine which user has locked a given record from VB6.

I know I can use sp_lock and sp_who, and match up the data to determine
which users have locked records in my database, however I haven't seen a
way to match the specific user to the specific record. What am I
missing here?


To echo what Dan said: you are barking up the wrong tree. The locking
mechanism in SQL Server is there to ensure atomicity of transactions.
If you have business requirements that makes it necessary one user to
reserve a record, and another user to see who has it reserved, you should
roll your own.

To this end, you probably need a few columns to the table with username,
time for the reservation, and possibly some more information. One thing that
you need to consider is that a reservation may become stale. That is, the
user who makes the reservation never completes the operation.

You should in no way rely on SQL Server locking mechanism, and you should
absolutely not keep locks while waiting for user input. This can cause
your application to grind to a standstill.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
Another problem that you could face with this approach is that when a
user retrieves data, you are not sure as to if they retrieve it for
update or for display only. Also, some IDEs allow the user to retrieve
multiple records from the database into a local buffer allowing the
user to scroll through them locally rather then keeping cursors open on
the database. The buffers can then be updated with a large transaction
at the end updating all changes for all records at once. Sort of the
same approach users take when updating a spreadsheet or word document.
Open the file, make changes then save the changes.

All this needs to be taken into concideration when deciding on the
locking mechanism used in your applications.

--
David Rowland
MS SQL Server DBMonitor author
http://dbmonitor.tripod.com

Jul 23 '05 #5
"David C. Barber" <da***@NOSPAMdbarber.com> wrote in message
news:4e********************@comcast.com...
I'm trying to determine which user has locked a given record from VB6.

I know I can use sp_lock and sp_who, and match up the data to determine
which users have locked records in my database, however I haven't seen a
way
to match the specific user to the specific record. What am I missing
here?

Thanks!

*David*


Further to the good answers you already have.

Should you find that pessimistic locking is a real must for some reason.
There's another approach to consider.
This is called soft locking.
It ain't really a lock in database terms at all.

With this you have one or two extra columns appended to each table.
User (optional ) and datetime.
When the user wants to mark data as locked, you lock, read, update the user
and datetime stamp.
When the changes are applied back or the user wants to free up the record,
the user is blanked and the datetime set to null.

The datetime is there so you can check to see if anyone's gone and left
their data locked for some inordinate amount of time.

This approach can be handy for those sort of apps where someone wants to
copy some data to a laptop, go off on a site visit or somesuch, update the
data on their laptop at clients or in transit and then eventually write it
all back when they're next in the office.

The downsides of softlocking are that you write updates to lock and unlock;
you can end up with everyone leaving locks all over the show if you're not
careful and your users don't match up to expectations.

Often, pessimistic is suffiicient.
--
Regards,
Andy O'Neill
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
1
by: Dudley Joseph | last post by:
Hi Ive got an Access97 db with a record in one of the tables that appears to be locked by another user even though no one is using it and the ..ldb confirms this. I need to delete this record...
6
by: DebbieG | last post by:
I have created a database for a client and was told that it was to be a one-user database. Well, you know the next statement ... now they want 3 people to be able to use the database. (FYI, I...
5
by: MLH | last post by:
Anyone remember how to determine a particular record's record number (Access 2.0 table question)?
1
by: andrew.newell | last post by:
Hi, I use MS Access to connect to and SQL Database this has been working fine until recently. Whenever I add a new record (post record 723) it does not allow me to change it. My DBA has...
1
by: pj | last post by:
Testing a database on a standalone machine gives the message 'Record currently locked by another user'. The record then presents '#Error' in each of the fields. The message repeats itself on screen...
3
by: Daniel | last post by:
Hello, I am trying to pass the slection made by a user to a javscript function using the onchange event. The problem is I can get the index but not the actual value. As my list is variable...
1
by: sling blade | last post by:
Hi, I have an AJAX PopupControl on a page and I use this control to allow a user to change the value of a table's header row. How can I tell what the user has selected? FYI: The...
2
by: Ice Vato | last post by:
Hi there. I'm using Microsoft visual studio 2008 and trying to find out if a user account on a local machine is locked ?? Any ideas as to how i can do this??...I've been following this example...
8
by: AnnMV8 | last post by:
I have set the Record Locked property to Edited Record so only one user can make changes at a time (using Access 2003). The circle with the line through it appears but everyone is freaking out that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.