2
votes

I am using the TADOConnection object in Delphi XE but this appears to be an ADO issue, not a Delphi issue:

Scenario: I am trying to close and free a TADOConnection object connected to Sybase. The connection is waiting for a response from a remote Sybase server after sending a long running query to Sybase - in the interim the user decided it's taking too long for a response and wants to abort the process.

Problem: When trying to close or free the ADOConnection object when it is waiting for the Sybase response, I receive this error message:

"Operation cannot be performed while executing asynchronously", and my calls to close/free fail. So, when aborting the process I always end up with a leak and an orphan connection - not the end of the world in my case, but not desirable either.

This message corresponds to ADO Error 3711-adErrStillExecuting - Operation cannot be performed while executing asynchronously.

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms681549%28v=vs.85%29.aspx

Question: How can I change the state of the ADOConnection object so that it is no longer waiting for the Sybase response, which should allow me to call TADOConnection.close and TADOConnection.free.

I have access to the ADOConnection itself via the Delphi TADOConnection wrapper so I can use whatever is available in the ADO TLB to accomplish this.

Note - I have not explicitely instructed ADO to perform an asynchronous operation- I assume that this is the default in the context in which I am running (thread spawned within a TISAPI application response). Regardless, I assume that if the ADO call was blocking it would be more even more difficult to abort.

1
Is there a reason you can't have the abort wait (in a thread) for the completion and then close normally? - Warren P
The architecture is a bit complex here - I've only explained the relevant part - an explicit abort at the time is the most efficient way to get this done and requires the least code mods. I could implement mechanisms to negotiate the issue the way you suggested - I considerd that - but not worth the trouble - ISAPI app and Sybase have plenty of resources and are periodically recycled anyhow. Just looking for a quick and dirty answer to the question. - Vector

1 Answers

3
votes

look at this response.

In particular the DataSet.Recordset.Cancel; part. You need to cancel the query first before you close the connection.