Working around ADO Error 3711: "Operation cannot be performed while executing asynchronously"

6.4k views Asked by At

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

There are 1 answers

1
whosrdaddy On BEST ANSWER

look at this response.

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