title: Working around ADO Error 3711: "Operation cannot be performed while executing asynchronously"
body: <p><strong>I am using the TADOConnection object in Delphi XE but this appears to be an ADO issue, not a Delphi issue:</strong> </p>
  
  <p><strong>Scenario:</strong> 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.</p>
  
  <p><strong>Problem:</strong> When trying to close or free the ADOConnection object when it is waiting for the Sybase response, I receive this error message:</p>
  
  <p><strong>"Operation cannot be performed while executing asynchronously"</strong>, 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.</p>
  
  <p><strong>This message corresponds to 
  ADO Error 3711-adErrStillExecuting - Operation cannot be performed while executing asynchronously.</strong></p>
  
  <p><strong>See <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681549%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms681549%28v=vs.85%29.aspx</a></strong></p>
  
  <p><strong>Question:</strong> 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. </p>
  
  <p>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.</p>
  
  <p>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.</p>