TUniLoader: How to catch error in PutColumnData?
Posted: Sun 13 May 2018 21:13
We use Unidac 7.2.7 with Delphi XE10.2.3. I use TUniLoader to transfer data between two databases (from MSAccess to SQL Server). Due to certain reasons the tables in both databases are not exactly equal. In SQL Server we use "smalldatetime" for DateTime (with reduced accuracy compared to "normal" date fields), whereas in MSAccess it is a "normal" DateTime field. The table contains measurement data with field names "StationID" (integer), "Date_Time" (Date and Time of the measurement) and the value of the measurement. The Primary key is "StationID" and "Date_Time". In can happen, that two measurement are made within a few milliseconds. In MSAccess (with the "normal" Date/time field) this is no problem, but when transferring the data to MSSQL (with reduced accuracy) it is (primary key violation). I want to skip these values, if a primary key violation occurs. I tried to catch the exception with
try
...PutColumnData
except
end
but it does not help. If a exception occurs, all other calls to PutColumnData seem to be "contaminated"
Here is an example of my code:
try
...PutColumnData
except
end
but it does not help. If a exception occurs, all other calls to PutColumnData seem to be "contaminated"
Here is an example of my code:
Code: Select all
procedure TFrm_Migration.ldrDstPutData(Sender: TDALoader);
var
i, irow, j: integer;
begin
irow := 0;
while not tblSrc.Eof do // tblSrc is a TUniTable, connected to MSAccess-DB
begin
inc( irow );
for j := 0 to tblSrc.Fields.Count - 1 do
begin
if not tblSrc.Fields[j].IsNull then
try
ldrDst.PutColumnData( tblSrc.Fields[j].FieldName, irow, tblSrc.Fields[j].Value ); // ldrDst is TUniLoader, connected to SQL-Server
except
end;
end;
tblSrc.Next;
end;
end;