Mac OSX FMX TMSQuery AV and crash reading image from broken connection
Posted: Tue  30 Jan 2018 16:59
				
				Hi,
Using my FMX-App I am fetching records from a remote SQL-Server to save them in a local database on my Mac. This might take several minutes ...
Situation 1, "select ID, Match, Image from Pictures':
When the connection to the SQL-Server breaks while fetching records an AV occurs on the Mac in my Firemonkey App and also it closes unexpectedly (see my code for comments) and message from PAServer: "Exception EInvalidOp in Modul Project10 at 0003B8AF, Invalid Floatingpoint-operation.
Situation 2, "select ID, Match from Pictures":
When the connection to the SQL-Server breaks while fetching records and CPU% goes to 99.7% on the Mac in my Firemonkey App and it hangs for ever.
MAC: OSX 10.13.2
Delphi: TOKYO 10.2.2
SDAC: 8.04
			Using my FMX-App I am fetching records from a remote SQL-Server to save them in a local database on my Mac. This might take several minutes ...
Situation 1, "select ID, Match, Image from Pictures':
When the connection to the SQL-Server breaks while fetching records an AV occurs on the Mac in my Firemonkey App and also it closes unexpectedly (see my code for comments) and message from PAServer: "Exception EInvalidOp in Modul Project10 at 0003B8AF, Invalid Floatingpoint-operation.
Situation 2, "select ID, Match from Pictures":
When the connection to the SQL-Server breaks while fetching records and CPU% goes to 99.7% on the Mac in my Firemonkey App and it hangs for ever.
MAC: OSX 10.13.2
Delphi: TOKYO 10.2.2
SDAC: 8.04
Code: Select all
procedure TForm14.ButtonRunClick(Sender: TObject);
var
  MSConnection : TMSConnection;
  MSQuery      : TMSQuery;
  i            : Integer;
begin
  MSConnection                              := TMSConnection.Create(self);
  MSConnection.ConnectionTimeout            := 5;
  MSConnection.Server                       := 'SQLServer';
  MSConnection.Username                     := 'User';
  MSConnection.Password                     := 'Password';
  MSConnection.Database                     := 'Database';
  MSConnection.LoginPrompt                  := false;
  MSConnection.Options.Provider             := prDirect;
  MSConnection.Options.AllowImplicitConnect := false;
  MSQuery                       := TMSQuery.Create(self);
  MSQuery.Connection            := MSConnection;
  MSQuery.Options.QueryRecCount := true;
  MSQuery.SmartFetch.Enabled    := true;
  MSQuery.SQL.Text              := 'select ID, MATCH, Image from PICTURE';
  MSQuery.KeyFields             := 'ID';
  i := 0;
  try
    MSConnection.connected := true;
  except
    MSQuery.Active         := false;
    MSConnection.connected := false;
    Memo1.Lines.add('Error Connection.Open');
    abort;
  end;
  try
    MSQuery.Active         := true;
    Progressbar1.Max       := MSQuery.RecordCount;
  except
    MSQuery.Active         := false;
    MSConnection.connected := false;
    Memo1.Lines.add('Error Query.Open');
    abort;
  end;
  try
    MSQuery.First;
  except
    MSQuery.Active         := false;
    MSConnection.connected := false;
    Memo1.Lines.add('Error Query.First');
    abort;
  end;
  while i < Progressbar1.Max do begin
    try
      // AV occurs when I manually break the Connection by closing the VPN
      label1.Text := MSQuery.FieldByName('Match').AsString;
    except
      MSQuery.Active         := false;
      MSConnection.connected := false;
      Memo1.Lines.add('Error reading Query.Match');
      // here programm quits unexpectedly
      abort;
    end;
    try
      MSQuery.Next;
    except
      MSQuery.Active         := false;
      MSConnection.connected := false;
      Memo1.Lines.add('Error Query.Next');
      abort;
    end;
    inc(i);
    ProgressBar1.Value := i;
    Application.ProcessMessages;
  end;
end;