ADO componenti:
darei una prova per i dati asincrono recupero. Quando eseguirai la query, ti ricorderai quando hai iniziato e ogni volta che l'evento OnFetchProgress
si attiva, controllerai se lo EventStatus
è ancora nello stato esOK
e controlla il tempo trascorso dall'esecuzione della query. Se è scaduto, è possibile annullare il recupero dei dati utilizzando il metodo Cancel
sul set di dati.
volevo usare qualcosa come il seguente pseudocodice (non testato):
var
FQueryStart: DWORD;
procedure TForm1.FormCreate(Sender: TObject);
begin
// configure the asynchronous data fetch for dataset
ADOQuery1.ExecuteOptions := [eoAsyncExecute, eoAsyncFetchNonBlocking];
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// store the query execution starting time and execute a query
FQueryStart := GetTickCount;
ADOQuery1.SQL.Text := 'SELECT * FROM Table';
ADOQuery1.Open;
end;
procedure TForm1.ADOQuery1FetchProgress(DataSet: TCustomADODataSet; Progress,
MaxProgress: Integer; var EventStatus: TEventStatus);
begin
// if the fetch progress is in esOK (adStatusOK) status and the time since
// the query has been executed (5000 ms) elapsed, cancel the query
if (EventStatus = esOK) and (GetTickCount - FQueryStart >= 5000) then
DataSet.Cancel;
end;
Cosa vuoi che accada quando è stato raggiunto 5 secondi? Un'eccezione che puoi gestire o qualcos'altro? E che edizione stai usando (forse Resource Governor può aiutarti qui). –
Vedere anche http://stackoverflow.com/questions/5077051/ado-components-commandtimeout - 'CommandTimeout' può essere d'aiuto ma può dipendere da un paio di altri fattori. –
Forse dovresti evitare di iniziare query che richiedono ore per essere completate. –