none
What is covered by SqlCommand CommandTimeout? RRS feed

  • Question

  • Hi,

    I am just wondering what command execution parts are covered by SqlCommand CommandTimeout property? The note on MSDN makes me confused "For example, with a 30 second time out, if Read requires two network packets, then it has 30 seconds to read both network packets. If you call Read again, it will have another 30 seconds to read any data that it requires.". To me, it is like everytime calling reader.Read(), we have independent timeout values which does not make sense...

    As an easy example,

    {

      SqlCommand command = new SqlCommand(queryString, connection);

      command.CommandTimeout = 10;

      SqlDataReader reader = command.ExecuteReader();

      while(reader.Read())

      {

      }

    }

    Should the time spent on command.ExecuteReader() and all the reader.Read() be cumulative for timeout 10s? Or command.ExecuteReader() has 10s and every reader.Read() has its own 10s?

    Thanks:)


    Tuesday, July 7, 2015 6:52 PM

Answers

  • ExecuteReader and Read are separate requests, each with their own ten second timeout limit.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, July 8, 2015 2:01 PM

All replies

  • ExecuteReader and Read are separate requests, each with their own ten second timeout limit.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, July 8, 2015 2:01 PM
  • Hi
    Katrinawyh,

    As far as i know, the 30s means that the time during command.ExecuteReader() and
    return the result assembly。

    The article said when you call the Reader() again, I think it should mean you call the
    ExecuteReader() and Read(). You could get another 30s TimeOut.


    If you have any other concern regarding this issue, please feel free to let me know.

    Best regards,

    Youjun Tang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, July 9, 2015 2:35 AM
  • I've read some source code of SqlDataReader, in which it passes the whole value of CommandTimeout to Read() method. So I am kinda agree with Paul, all the operations should have independent timeout. Especially the comments in SqlDataReader class as following:

    private void SetTimeout(long timeoutMilliseconds) {

        // WebData 111653,112003 -- we now set timeouts per operation, not

        // per command (it's not supposed to be a cumulative per command).

        TdsParserStateObject stateObj = _stateObj;

        if (null != stateObj) {

            stateObj.SetTimeoutMilliseconds(timeoutMilliseconds);

        }

    }

    Thursday, July 9, 2015 3:20 AM
  • Hi Katrinawyh,

    You're right, Per operation has 30s timeout, It is the same as the point in my reply.

    I explained that the 30s is the time during the ExecuteReader() and Reader(). Maybe my statament is vague, Sorry for that.

    Regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 9, 2015 7:30 AM