Solved

Delphi Error Trap For Failed Stored Procedure

Posted on 2014-04-04
4
521 Views
Last Modified: 2014-04-16
I have a Delphi 2006 application which calls several ADO Stored Procedures.
My problem is that the SP returns a Transaction Deadlock every now and then and If have implemented the standard Delphi error trapping but it does not seem to work ?

Is there another way of catching these errors so my application does not crash ?

        Memo1.Text:=Memo1.Text+'Start Recalc'+FormatDateTime('HH:MM:ss',Time)+#13+#10;
        Brk:=1;
        while Brk=1 do
           try
             Try
             ADOCAN.ExecProc;
           except on E:Exception do
              Begin
                Memo1.Text:=Memo1.Text+'ADOCan Error';
                Sleep(10000);
              End;
             End;
           finally
             Brk:=2;

        end;
        Memo1.Text:=Memo1.Text+'End Recalc'+FormatDateTime('HH:MM:ss',Time)+#13+#10;

Thanks

Tim
0
Comment
Question by:Hornwood
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39977679
why this?

Sleep(10000);
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39977861
I suggest to use:
  DBConn.BeginTrans;
  try
    ADOCAN.ExecProc;
    DBConn.CommitTrans; //on success, commit the changes;
  except
    DBConn.RollbackTrans; //on failure, undo the changes;
  end;

Open in new window

DBConn is AdoConnection, and your ADOCAN is linked to it.

... your procedure can be called using TADOCommand component too:
q: TADOCommand;
....
    q.CommandText:='exec procName param1, prarm2';
    q.Execute;

Open in new window

0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39977922
Your while loop does not make any sense. The wrapped code will just run once, so what is the point of the while loop?

I would have written that block of code as follows (note the e.message I added):
Try
  Memo1.lines.add('Start Recalc '+FormatDateTime('HH:MM:ss',Time));
  ADOCAN.ExecProc;
  Memo1.lines.add('End Recalc '+FormatDateTime('HH:MM:ss',Time));
except on E:Exception 
  do Memo1.lines.add('ADOCan Error: ' + e.message);      
End;	

Open in new window


can you elaborate on "...implemented the standard Delphi error trapping but it does not seem to work"? What is not working as expected? What error are you getting?
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39979957
you will never be able to solve the deadlock from the delphi app
you need to look at the stored procedure

somewhere you are locking row A, someone else is locking row B
then someone else wants to lock row A and then you want to lock row B
that's your deadlock

find what 2 rows you are locking, and then see if anyone can do it in the reverse order
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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