ADO.Net DataReader timeout error

I am using ADO.Net + C # + VSTS 2008 + ADO.Net to connect to SQL Server 2008 Enterprise. I use almost the same template / pattern mentioned here - using ADO.Net DataReader to retrieve the data of one record (row) by one record (row).

http://msdn.microsoft.com/en-us/library/haa3afyz.aspx

My question is: if I set the SqlCommand timeout in this example, 1. I think the timeout applies to how much time we could use as the maximum value to retrieve one row, rather than a full timeout for the entire input cycle write data?

BTW: loop I mean

while (reader.Read()) { Console.WriteLine("{0}\t{1}", reader.GetInt32(0), reader.GetString(1)); } 

2. and this timeout only matters for how long it takes to retrieve data from the database, and this timeout has nothing to do with how much time we deal with each record (for example, if we set a time out for 20 seconds, and if it takes 1 second to get one data record from the database, and for my application logic it takes 30 seconds to process data input, the timeout will never happen).

Correct understanding?

+6
c # visual-studio-2008 sqldatareader
source share
2 answers

The command timeout that you can set refers to how long you provide ADO.NET to do your job.

If you call cmdQuery.ExecuteNonQuery() , which returns nothing and executes an SQL statement, this is the time it takes to execute this statement.

If you call cmdQuery.ExecuteReader() , which returns a data reader, this is the time ADO.NET needs to create / create this device to read data so that you can use it.

If you call cmdQuery.ExecuteScalar() , which returns a single scalar value, this is the time it takes to execute the query and get this single result.

If you use dataAdapter.Fill() to populate a data table or dataset, this is the time it takes ADO.NET to retrieve the data, and then populate the data table or dataset.

In general: the timeout is applied to that part of the task that ADO.NET can perform - it executes the operator, fills the data set, returns a scalar value.

Of course, it does NOT apply to the time it takes YOU to repeat the results (in the case of reading data). That would not make sense ...

Mark

+10
source share

Yes you are right. CommandTimeout means the time it takes to start the database (any command)

+2
source share

All Articles