large inserts take long time

From: Jeroen Vandezande (NoSpam)
Date: 04/23/04


Date: Fri, 23 Apr 2004 15:35:47 +0200

Hi,

I have a application were an embedded device sends pressure data from a
pump.
This data is stored in a internal data structure (ObjectList).
When the device disconnects the program dumps this data to the database (MS
SQL).
I use ADO in Delphi 7 to connect to this DB.
This takes about 30 secs to write 5000 records. This is a long time, because
I am not sure what is going to happen when 20 or 30 devices start dumping
data on the program.
This is the code that puts the data in the database:

Procedure TMainForm.LoggerServerDisconnect(AThread: TIdPeerThread);
Var
  I, SampleID: Integer;
Begin

AThread.Synchronize(TCustomTdPeerThread(AThread).SetDisconnectedOnMainForm);
  If TCustomTdPeerThread(AThread).DataList.Count > 5 Then
  Begin
    AThread.Synchronize(TCustomTdPeerThread(AThread).SetWritingOnMainForm);
    SamplesDataSet.Insert;
    SamplesDataSet_CartridgeID.Value :=
TCustomTdPeerThread(AThread).CartridgeID;
    SamplesDataSet_PumpID.Value := TCustomTdPeerThread(AThread).PumpID;
    SamplesDataSet_CartridgeSerialNumber.AsString :=
TCustomTdPeerThread(AThread).CartridgeBarcode;
    SamplesDataSet_UserID.Value := TCustomTdPeerThread(AThread).UserID;
    SamplesDataSet.Post;
    SampleID := SamplesDataSet_ID.Value;
    For I := 0 To TCustomTdPeerThread(AThread).DataList.Count - 1 Do
    Begin
      If TCustomTdPeerThread(AThread).DataList.Items[I].Time > 0 Then
      Begin
        SamplesDataDataSet.Insert;
        SamplesDataDataSet_SampleID.Value := SampleID;
        SamplesDataDataSet_SampleTime.Value :=
TCustomTdPeerThread(AThread).DataList.Items[I].Time;
        SamplesDataDataSet_Pressure.Value :=
TCustomTdPeerThread(AThread).DataList.Items[I].Pressure;
        SamplesDataDataSet_Flow.Value :=
TCustomTdPeerThread(AThread).DataList.Items[I].Flow;
      End;
    End;
    SamplesDataDataSet.Post;

AThread.Synchronize(TCustomTdPeerThread(AThread).SetWritingDoneOnMainForm);
  End;
End;

Is there a way to do an insert with more than one record at a time?

Best regards,

Jeroen Vandezande.