在 `SqlCommand` 中,`CommandTimeout` 实际代表什么时间跨度?

In a `SqlCommand`, what timespan does the `CommandTimeout` actually represent?

我正在使用 SqlConnectionSqlCommandSqlReader 查询 Microsoft SQL 数据库,与 https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader

中描述的非常相似

现在,SqlCommand 允许设置 CommandTimeout,我是这样做的(简化):

using (SqlConnection connection = GetConnection()) {
    connection.Open();
    using (SqlCommand command = connection.CreateCommand()) {

        command.CommandText = query; //My custom SQL query
        command.CommandType = CommandType.Text;

        //Set Timeout
        command.CommandTimeout = timeout.Value; //My custom timeout

        using (SqlDataReader reader = command.ExecuteReader()) {
            while (reader.Read()) {
                //Read row by row and do stuff
            }
        }
    }
}

我的问题是,超时实际上适用于什么?是吗

MSDN 和网络上似乎都没有专门的文档。

它将应用于对数据库执行命令的时间,即 command.ExecuteReader() 在您开始读取记录时已完成。您可以通过在 while 之后放置一个断点并坐在那里进行测试 - 您不会超时。