ADO components CommandTimeout

后端 未结 3 1604
后悔当初
后悔当初 2021-01-12 13:26

I have a problem with settings of the query execution timeout with TADOQuery, TADOCommand or TADODataSet (I\'ve tried it with each one). I have a tiny application, which con

3条回答
  •  醉话见心
    2021-01-12 14:15

    Following is what we use to set the timeout to 300 for our long running reports.

      //***** Fix setting CommandTimeOut. 
      //      CommandTimeOut "should" get the timeout value from its connection. 
      //      This is not supported in ADODB (using Delphi5)
      TADODataSet(qryReport).CommandTimeout := ADOConnection.CommandTimeout;
    

    Edit

    Executing following piece of code on my Development Machine times out after 1 second.

    • The query has a connectionstring to our SQLServer production database.
    • The script (tries to) runs for 10 seconds
    • After one second, I get a TimeOut exception

    Test

    procedure TForm1.btn1Click(Sender: TObject);
    const
      SSQL: string =
        'DECLARE    @intLoop int '#13#10
        + 'SET @intLoop = 10 '#13#10
        + 'WHILE @intLoop > 1 '#13#10
        + 'BEGIN '#13#10
        + ' SELECT  @intLoop, GetDate() '#13#10
        + ' WAITFOR DELAY ''00:00:01'' '#13#10
        + ' SELECT  @intLoop = @intLoop -1 '#13#10
        + 'END ';
    begin
      qry1.SQL.Text := SSQL;
      TADODataSet(qry1).CommandTimeout := 1;
      qry1.ExecSQL;
    end;
    

提交回复
热议问题