R
Rodrigo Meneses
Hello.
The cancel command interrupts the current query being executed... but when I
run another query using the same connection (or another connection using
connection pooling) sometimes I get another "Operation Cancelled by user"
exception. It appears that the Cancel command runs asynchronously and the
connection associated to the command remains in a "Dirty" for a while making
future calls to ExecuteReader on the command throws an Operation Cancelled
by user.
Does somebody know how to control this? How to know when a command is
completly cancelled?
Some code:
string select = "SELECT * FROM A";
SqlConnection c = new SqlConnection(sqlConnection1.ConnectionString);
c.Open();
SqlCommand command = new SqlCommand(select, c);
SqlDataReader r = command.ExecuteReader();
command.Cancel();
command3.Dispose();
r.Close();
c.Close();
SqlConnection c2 = new SqlConnection(sqlConnection1.ConnectionString);
c2.Open();
SqlCommand command2 = new SqlCommand("select top * from B", c2);
SqlDataReader read = command2.ExecuteReader();
while (read.Read()) ///sometimes this line throws an "Operation Cancelled
by user exception" because of the "command.Cancel()"
{
read.ToString();
}
c2.Close();
c2.Dispose();
Thanks
The cancel command interrupts the current query being executed... but when I
run another query using the same connection (or another connection using
connection pooling) sometimes I get another "Operation Cancelled by user"
exception. It appears that the Cancel command runs asynchronously and the
connection associated to the command remains in a "Dirty" for a while making
future calls to ExecuteReader on the command throws an Operation Cancelled
by user.
Does somebody know how to control this? How to know when a command is
completly cancelled?
Some code:
string select = "SELECT * FROM A";
SqlConnection c = new SqlConnection(sqlConnection1.ConnectionString);
c.Open();
SqlCommand command = new SqlCommand(select, c);
SqlDataReader r = command.ExecuteReader();
command.Cancel();
command3.Dispose();
r.Close();
c.Close();
SqlConnection c2 = new SqlConnection(sqlConnection1.ConnectionString);
c2.Open();
SqlCommand command2 = new SqlCommand("select top * from B", c2);
SqlDataReader read = command2.ExecuteReader();
while (read.Read()) ///sometimes this line throws an "Operation Cancelled
by user exception" because of the "command.Cancel()"
{
read.ToString();
}
c2.Close();
c2.Dispose();
Thanks