Solved

Delphi Error Trap For Failed Stored Procedure

Posted on 2014-04-04
4
527 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql server insert 12 40
Why i am getting a star, SSMS does not show me any error. Division Error 5 32
SQL Error - Query 6 41
Connection to multiple databases 13 25
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 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