CommandTimeout for DataReader
Posted: Mon 04 Nov 2013 14:56
Hi All,
The problem is:
The command's timeout is not working for DataReader.
You can reproduce it when you try to SELECT data from a Large table.
Or, the problem appears when other operation blocks a rows in the table.
P.S. You will get a TimeoutException when you will execute commands such as pg_sleep().
The problem is:
The command's timeout is not working for DataReader.
You can reproduce it when you try to SELECT data from a Large table.
Or, the problem appears when other operation blocks a rows in the table.
Code: Select all
using (PgSqlConnection connection = new PgSqlConnection("string"))
{
PgSqlCommand command = connection.CreateCommand();
command.CommandTimeout = 1;
command.CommandText = "SELECT * FROM public.LargeTable";
connection.Open();
using (PgSqlDataReader reader = command.ExecuteReader()) // this line will block current thread forever
{
while (reader.Read()) ;
}
connection.Close();
}