|
 |
activex_data_objects thread: Need help with Record-level locking in ADO
Message #1 by elisabeth_doreste@h... on Thu, 10 Oct 2002 16:41:20
|
|
Hi!
Does anybody know how I can lock a specific record in a multiuser
database? This does not seem to work when I open two sessions of my
program that communicates with the database.
If I enter a dialog for editing a client, then start up another session
of the program and try to edit the same client no locking has ocurred.
When opening the dialog I run:
pMyRecordSet->Open(SELECT * FROM MYTABLE WHERE PNo = aPNo, _variant_t
((IDispatch *) pConnection, true), adOpenKeyset, adLockPessimistic,
adCmdText);
I set pessimistic locking when entering the dialog and set it to
optimistic when I have saved and closed the dialog. Anybody that has any
idea?
(I program in VC++ using ADO)
Thanks beforehand!
/ Elisabeth
Message #2 by R MALY GBIPS MIS <maly@m...> on Fri, 11 Oct 2002 09:02:54 +0100
|
|
IMHO
The most effective way of locking a database record is to do it manually. I
assume that you are SQL Server which only locks when you are physically
doing the update. Which does nothing to prevent the following scenerio :
Person A gets some data,
Person B getting the same set of data.
Person A makes some changes and saves them,
Person B makes some other changes then saves them over Person A's changes
and in turn corrupting the data.
I have a isLocked field that is null when locked but has a user name, id
etc. when it is locked. When you return your recordset you can evaluate
this field if it is locked you an then chuck up an error message "Field is
locked by x". If it is not locked you then update the field. Not
forgetting to clear it when they close the form etc.
Subject: Need help with Record-level locking in ADO
From: elisabeth_doreste@h...
Date: Thu, 10 Oct 2002 16:41:20
X-Message-Number: 3
Hi!
Does anybody know how I can lock a specific record in a multiuser
database? This does not seem to work when I open two sessions of my
program that communicates with the database.
If I enter a dialog for editing a client, then start up another session
of the program and try to edit the same client no locking has ocurred.
When opening the dialog I run:
pMyRecordSet->Open(SELECT * FROM MYTABLE WHERE PNo = aPNo, _variant_t
((IDispatch *) pConnection, true), adOpenKeyset, adLockPessimistic,
adCmdText);
I set pessimistic locking when entering the dialog and set it to
optimistic when I have saved and closed the dialog. Anybody that has any
idea?
(I program in VC++ using ADO)
Thanks beforehand!
/ Elisabeth
---
END OF DIGEST
|
|
 |