【发布时间】:2019-03-16 06:18:06
【问题描述】:
我正在使用 SqlConnection、SqlCommand 和 SqlReader 查询 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
}
}
}
}
我的问题是,超时实际上适用于什么?是吗
- 在
ExecuteReader()中花费的时间 - 在
Read()中花费的时间 - 这两样
- 还有别的吗?
MSDN 和网络上似乎都没有这方面的具体文档。
【问题讨论】:
标签: sql .net timeout sqldatareader sqlcommand