Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi Error Trap For Failed Stored Procedure

Posted on 2014-04-04
4
Medium Priority
?
580 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 28

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 38

Accepted Solution

by:
Geert Gruwez earned 1500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline
Suggested Courses

971 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