Trapping MS SQL DB_E_INTEGRITYVIOLATION

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Locked
davidkennedy
Posts: 18
Joined: Fri 07 Jul 2006 16:21

Trapping MS SQL DB_E_INTEGRITYVIOLATION

Post by davidkennedy » Tue 26 Sep 2006 04:09

I am tasked with converting many Delphi tables to MS SQL. Whenever I find an DB_E_INTEGRITYVIOLATION violation of trying to write an orphan record into the MS SQL database, it blows up with an error message and halts operation (in the IDE and running as an .exe). I posted a message last week that you were kind enough to describe the error checking code, but the problem is that when the execution blows in the TRY section attempting a RECORD.POST it never gets to the EXCEPT statement to 'gently' execute the error resolution routine. Here is the example,
var - add these;
E, i : integer;

The nerveracking part of trying to catch the MSSQL exception is that it doesn't ever move into the exception (EXCEPT) area. When I trace this through the code, the RECORD.POST throws the MSSQL exception in the TRY part, and doesn't drop out to the EXCEPT loop. The 'catch 22' part of all this is that I can't then put the exception code in the TRY part because the error exception objects only have scope in the EXCEPT area. Here's the code showing this phenomina;
try
OutTable.Post;
except
on E: EOLEDBError do
begin
for i := 0 to EOLEDBError(E).ErrorCount - 1 do
if EOLEDBError(E).Errors.ErrorCode = DB_E_INTEGRITYVIOLATION then
begin
ErrTable.insert;
ErrTable.FieldByName('IntKey1').Value := KeyInt;
ErrTable.FieldByName('DateKey').Value := KeyDate;
ErrTable.FieldByName('RecDesc').Value := 'Tx Convert';
ErrTable.FieldByName('StrKey2').Value := 'orphan';
ErrTable.post;
end;
break;
end;
I need to find a way to A: write the record, B: write the error record and C: move on to the next input record. Thank you.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 26 Sep 2006 08:55

Please send us (evgeniyD*crlab*com) a complete sample to demonstrate this problem, including script to create server objects. This will help us to find and test the solution to the problem.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 29 Sep 2006 12:36

This topic is duplicated.
Please see original topic at http://crlab.com/forums/viewtopic.php?t=7488.

Locked