Cancel query execution

N

Nick

I've got the small section of code below running in a thread. I need to give
the user the ability to cancel the operation. Is there a way to do that?
There are times when it could take a long time to fill and they may want to
cancel. The query could be an insert, update, or delete.

OdbcDataAdapter _adp = new OdbcDataAdapter(_sql, _connection);
DataTable _dt = new DataTable();
_adp.Fill(_dt);

Thanks for any help, I sincerely appreciate it.

Nick
 
J

Jeff Johnson

I've got the small section of code below running in a thread. I need to
give
the user the ability to cancel the operation. Is there a way to do that?
There are times when it could take a long time to fill and they may want
to
cancel. The query could be an insert, update, or delete.

OdbcDataAdapter _adp = new OdbcDataAdapter(_sql, _connection);
DataTable _dt = new DataTable();
_adp.Fill(_dt);

Thanks for any help, I sincerely appreciate it.

Because the Fill() method does not have the corresponding asynchronous
BeginFill() and EndFill() methods, I would say the answer is No, you cannot
cancel the method call because it is completely synchronous.

In fact, now that I look closely, ADO.NET does not seem to be big on
asynchronous methods. Old ADO used to give you the ability to execute a
query asynchronously and get updates via an event, but I don't see anything
similar. (I only use the basics of ADO.NET, so I could be missing
something.)

If you really need the ability to cancel then you'll probably have to use a
DataReader on a separate thread and fill your dataset manually, stopping if
the user presses the cancel button.
 
N

Nick

Because the Fill() method does not have the corresponding asynchronous
BeginFill() and EndFill() methods, I would say the answer is No, you cannot
cancel the method call because it is completely synchronous.

In fact, now that I look closely, ADO.NET does not seem to be big on
asynchronous methods. Old ADO used to give you the ability to execute a
query asynchronously and get updates via an event, but I don't see anything
similar. (I only use the basics of ADO.NET, so I could be missing
something.)

If you really need the ability to cancel then you'll probably have to use a
DataReader on a separate thread and fill your dataset manually, stopping if
the user presses the cancel button.
Thanks for your help. I'll look into that. Any idea what the performance
would be compared to using Fill()?

Thanks,
Nick
 
J

Jeff Johnson

Thanks for your help. I'll look into that. Any idea what the performance
would be compared to using Fill()?

Without decompiling the Fill() method itself to see what's happening under
the covers, no idea. How insanely big are these tables? Anyways, if your
users are already tiring of the operation, does it really matter...?
 
N

Nick

Without decompiling the Fill() method itself to see what's happening under
the covers, no idea. How insanely big are these tables? Anyways, if your
users are already tiring of the operation, does it really matter...?

Excellent point! It doesn't matter, I was just curious. The size of the
table can vary. Some are very small, others are ver, very large. I'll give it
a shot and let you know how it goes.

Thanks again for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top