Solved

Delphi Error Trap For Failed Stored Procedure

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

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 36

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

20 Experts available now in Live!

Get 1:1 Help Now