Solved

TQuery, record locked error when using Transaction control

Posted on 2000-05-02
10
482 Views
Last Modified: 2010-04-04
Hi
I was making a dialog containing several linked cached queries...and I tried to use transaction-control to enable the user to cancel all updates, or to commit. Everything seemed well until I tried to modify records more then once, then I got the message "Record lock failed".

I've now broken the problem down to one query and an UpdateSql, where I fire the UpdateSQL.Apply(ukModify) in the query's OnAfterPost. The second time the record is modified the same error occurs. If I remove the StartTransaction the error does not occur; however I've found no reason why it shouldn't be possible to use the transaction and rollback this way. The problem persists also when the query is closed and opened after each modification.

I'm using D4P, BDE 5.01 and Paradox tables.

Any advice?
0
Comment
Question by:Ottar
  • 6
  • 3
10 Comments
 
LVL 3

Expert Comment

by:shenqw
ID: 2771984
I think you must modify your code like this:


In Query1.OnAfterPost

procedure TForm1.Query1AfterPost(DataSet: TDataSet);
begin
  Query1.Database.StartTransaction;
  try
    Query1.ApplyUpdates;
    Query1.CommitUpdates;
    Query1.Database.Commit;
  except
    Query1.Database.Rollback;
  end;
end;


In Query1.OnUpdateReocrd

procedure TForm1.Query1UpdateRecord(DataSet: TDataSet; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
  UpdateSQL1.Apply(UpdateKind);
  UpdateAction:=uaApplied;
end;


Good Luck!

shenqw {B-)
0
 

Author Comment

by:Ottar
ID: 2773907
Thanks shenqw!
What you suggest works fine, and is according to the examples in Delphi-help.

But I want the user to have the possibility to regret and "roll" the situation back to what it was before the dialog was opened and any changes were done to the tables. How can I achive this when the changes, according to your example, are already commited to the database?

I understand that my attemt to start transaction on the first modification, and commit or rollback the database upon leaving the dialog is not the proper way to use these routines.

So I still need some advice.....
Ottar
0
 

Author Comment

by:Ottar
ID: 2778059
Adjusted points from 100 to 200
0
 

Author Comment

by:Ottar
ID: 2781728
Adjusted points from 200 to 300
0
 
LVL 1

Expert Comment

by:ronvp
ID: 2791698
May be I misunderstand, but I have a question, why do you want to commit the update in a after post event, that means that after any record is changed, you immendiately commit those changes. should you not commit any changes when the user closes the dialog with the OK botton and RollBack with the Cancel Button?

To release the lock, you may try the BDE function DbiRelRecordLock..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Ottar
ID: 2797636
Hi ronvp

My intention was originally NOT to commit the update in the AfterPost event. As you indicate, I rather want the changes to be committed when the OK-button is activated in the dialog, eventually rolled back on Cancel. But when trying to accomplish this I run into the record lock problem described initially.

I've earlier tried the DbiRelRecordLock without luck, and actually I would not like to implement procedures where this lock-situation occur.

So, the case is that I'm not able to make several changes without recordlock error unless I perform the committing after each update.

When trying, are you getting the same result?

Ottar
0
 
LVL 1

Expert Comment

by:ronvp
ID: 2799290
Ottar,

I have not tried this myself, but I am just thinking that with your query component, do you actually have requestlive set to false, this is just a idea, but it appears as if your record is actually locked by the standard edit method. Again I am not sure, but this may happen if you have query that can return a live result set and have request live set to True. (I have not checked this). A other thing you may like to try is to set AutoEdit to False in the Datasource component..

If you E-mail me you project, I will try to play with it...
0
 

Author Comment

by:Ottar
ID: 2805920
Hi ronvp

I can send you a small example code showing the problem.

Can I find your e-mail addr. here at EE?

Ottar
0
 
LVL 1

Accepted Solution

by:
ronvp earned 300 total points
ID: 2809696
Ottar, you should be able to just click on my name, but just to be sure:

ronvanpetegem@compuserve.com
0
 

Author Comment

by:Ottar
ID: 2826779
My record lock problem is not completly solved, as I still get an error when handeling too many cached records. (In the test we tried with 300 records) However, this seems to be due to limitations in BDE, and I therefore give this question the status accepted.

ronvp's help tracing the problem was excellent!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 189
Communication Between RC4 Delphi <-> PHP 3 100
Intraweb download file link ? 1 109
TEMBEDDEDWB how can i change its user agent ? 8 47
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now