How to cancel a running query
Posted: Tue 09 Oct 2012 09:43
Hi everybody,
Could you tell me how to cancel a query that takes a long time. For example select 1mln records. Like that:
As You can see, program hangs on a single line. I would like to have a Cancel button that will terminate this process.
Right now I run this code in another thread. Object that calls this method needs connection to database to be created and has dispose method - where I disconnect from database. So I use 'using' to create this object.
And now.. To stop that query I just kill this thread from another thread, but I don't think is a good idea (And it's not working well). Sometimes, after kill an error appears: NET: Unknown error 1. And then I can't execute nothing anymore. Always "NET: Unknown error 1" appears.
Could you tell me how to cancel this process ?
Could you tell me how to cancel a query that takes a long time. For example select 1mln records. Like that:
Code: Select all
public string ExecQuery(string cmd, out DataTable dt)
{
dt = new DataTable();
string error = "";
try
{
OracleCommand command = new OracleCommand(cmd, sqlConnection);
using (OracleDataReader rdr = command.ExecuteReader())
{
using (rdr)
{
dt.Load((IDataReader)rdr); // THIS LINE TAKES OVER 1 MINUTE
}
}
}
catch (Exception ex)
{
error = ex.Message;
return error;
}
return error;
}
Right now I run this code in another thread. Object that calls this method needs connection to database to be created and has dispose method - where I disconnect from database. So I use 'using' to create this object.
Code: Select all
using (DatabaseProvider dp = new DatabaseProvider())
{
this.Result = dp.ExecQuery(this.Query, out this.Dt);
}
Could you tell me how to cancel this process ?