SDAC

TMSSQL.CommandTimeout Property

Used to specify the wait time before terminating the attempt to execute a command and generating an error.

Class

TMSSQL

Syntax

property CommandTimeout: integer default 0;

Remarks

The time in seconds to wait for the command to execute.

The default value is 0. The 0 value indicates no limit (an attempt to execute a command will wait indefinitely).

If a command is successfully executed prior to the expiration of the seconds specified, CommandTimeout has no effect. Otherwise, the 'Query timeout expired' error is generated by SQL Server. This error has the DB_E_ABORTLIMITREACHED OLEDB error code.

For more information about OLEDB Errors, refer to http://technet.microsoft.com/en-us/library/ms171852.aspx

Samples

Delphi

MSSQL.CommandTimeout := 5; // wait 5 seconds for the command to execute
MSSQL.SQL.Text := 'long-lasting query';
try
  MSSQL.Execute;
except
  on E: EOLEDBError do begin
    if E.ErrorCode = DB_E_ABORTLIMITREACHED then // the 'Query timeout expired' error
      ShowMessage(E.Message);
    raise;
  end;
end;


Note: To run this code, it is needed to add the OLEDBAccess and OLEDBC units to the USES clause of the unit.

C++Builder

MSSQL->CommandTimeout = 5; // wait 5 seconds for the command to execute
MSSQL->SQL->Text = "long-lasting query";
try
{
  MSSQL->Execute();
}
catch (EOLEDBError &E)
{
  if (E.ErrorCode == DB_E_ABORTLIMITREACHED) // the 'Query timeout expired' error
    ShowMessage(E.Message);
  throw;
}


Note: To run this code, it is needed to include the oledberr.h header file to the unit.

See Also

© 1997-2024 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback