Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread "Cannot lock row" 1005 Error. Is it possible to return the UserID of the user accessing ...
Wed, Jun 22 2016 6:59 AMPermanent Link

Adam Brett

Orixa Systems

EDB works really well for me with Record-locking, without too much hard work.

My users seldom clash when editing records, however they do sometimes.

* 2 users both open record XXX at the same time & edit.
* User 1 posts.
* User 2 posts.

User 2 receives a 1005 Error.

This is fine.

However if User 1 edits the row and then leaves their desk/takes a call etc, User 2 is a bit stuck.

It would be really useful to have the following logic:

User 2 Posts.

Receives Error + "Cannot Post because User 1 is editing this record!"

Not sure whether this is possible or not. If it is it would be great to know how.
Wed, Jun 22 2016 7:22 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


I remember this being asked before - unfortunately I don't remember the answer. But a few questions for you anyway

1. Are you using optimistic / pessimistic locking
2. c/s or f/s
3. Do users log in with a unique ElevateDB ID

I'll see if I can find the posts my memory insist are there but its also saying it would only be possible if you use c/s and users log in.

The other alternative if you're using pessimistic locking is to look at switching to optimistic. It does put the onus on you to make sure the record hasn't been changed by someone else though.


Roy Lambert
Wed, Jun 22 2016 7:40 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam

The answer is yes

Check this thread out

http://www.elevatesoft.com/forums?action=view&category=edb&id=edb_general&msg=11682

There's a query in there which could be extended a bit to give what you want - it needs to be run as configuration rather than information or your own database

Roy Lambert
Thu, Jun 23 2016 5:27 AMPermanent Link

Adam Brett

Orixa Systems

Roy

You are priceless. Thanks.

In the spirit of sharing, here is a short code-fragment which provides a message to a user who tries to edit a record when it is being edited by another user.

The message includes the "User" and "Process" (which provides the Computer Name). In many cases this should help people to figure out who has trapped their record.


procedure TForm29.FormCreate(Sender: TObject);
begin
 gabDB.Connect; //this line creates all my Database and session objects.
 Q:= TabLiveQuery.Create(self); //this class is my own EDBQuery descendent,
                                                    //which on-create links to the DB objects above.
 Q.RequestSensitive:= true;
 Q.OnEditError:= QOnEditError;
end;

procedure TForm29.QOnEditError(Dataset: TDataset; E: EDatabaseError; var
   Action: TDataAction);
var
 aErr, aTableName: String;
begin
 if EEDBError(E).ErrorCode = 1005 then
   begin
     aErr:= E.Message;
     aErr:= StringReplace(aErr, 'ElevateDB Error #1005 Cannot lock the row in the table ', '', []);
     aErr:= StringReplace(aErr, '.', '', []);

     //ExecQ is an object I have written which allows me to return data quickly.
     //it includes the "DataToNiceStrings" method used below which just parses
     //fields and spits out text + line-feed characters.
     ExecQ.RefreshData(' SELECT ' +
                       '   SSL.SessionName,' +
                       '   SSL.ObjectName,' +
                       '   SSL.LockType,' +
                       '   SSL.Number as RowNumber,' +
                       '   SS.User,' +
                       '   SS.Process' +
                       ' FROM Configuration.ServerSessionLocks SSL' +
                       ' LEFT JOIN Configuration.ServerSessions SS ON (SS.ID = SSL.SessionID)' +
                       ' WHERE LockType = ''Row''' +
                       ' AND UPPER(ObjectName) = UPPER(''%s'') ',
                       [aErr]);
     Showmessage('CANNOT EDIT RECORD, ANOTHER USER IS ACCESSING IT: ' +#13+
                              ExecQ.DataToNiceStrings);
      ExecQ.Close;
      ExecQ.Unprepare;
   end;
end;
Thu, Jun 23 2016 6:37 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam

>You are priceless.

Actually I thought I was very reasonably priced Smiley

Roy
Image