TUniLoader: How to catch error in PutColumnData?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Emil1957
Posts: 12
Joined: Thu 04 Aug 2016 12:10

TUniLoader: How to catch error in PutColumnData?

Post by Emil1957 » 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:

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;

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: TUniLoader: How to catch error in PutColumnData?

Post by Stellar » Wed 16 May 2018 08:23

Unfortunately, there is no way to handle the exception and continue adding records using TUniLoader.
A different number of requests can be sent to the server depending on the amount of data being added. The TUniLoader technology does not allow you to determine what data was not added to the Database and skip unhandled data.

Post Reply