I'm retrieving huge amount of data from SQL Server. Everything works fine but when I try to close IDataReader inside using statement
try
{
using (SqlConnection con = new SqlConnection(connString))
{
con.Open();
using (SqlCommand command = new SqlCommand(sql_query, con))
{
command.CommandTimeout = 0;
using (IDataReader rdr = new SqlCommand(sql_query, con).ExecuteReader(CommandBehavior.SequentialAccess))
{
dataTable = GetDataTableFromDataReader(rdr);
}
....
I'm getting: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Would it be better to use something like rdr = null? Or is there another better solution how to close IDataReader?