Cancel Method

See Also        Applies To

Cancels execution of a pending asynchronous method call (ODBCDirect workspaces only).

Syntax

VOIDCancel(VOID);

Remarks

Use the Cancel method to terminate execution of an asynchronous Execute, MoveLast, OpenConnection, or OpenRecordset method call (that is, the method was invoked with the dbRunAsync option). Cancel will return a run-time error if dbRunAsync was not used in the method you are trying to terminate.

The following table shows what task is terminated when you use the Cancel method on a particular type of object.

If you call Cancel from a This asynchronous method is terminated
CdbConnection Execute or OpenConnection
CdbQueryDef Execute
CdbRecordset MoveLast or OpenRecordset

An error will occur if, following a Cancel method call, you try to reference the object that would have been created by an asynchronous OpenConnection or OpenRecordset call (that is, the CdbConnection or CdbRecordset object from which you called the Cancel method).

Usage

#include <afxole.h>
#include <dbdao.h>

CdbDBEngine         dben(...,dbUseODBC);
CdbWorkspace      wrkMain;
CdbConnect         conMain;

wrkMain = dben.CreateWorkspace("ODBCWorkspace", 
               _T("admin"), _T(""), dbUseODBC);
// Open the connection asynchronously.
conMain = wrkMain.OpenConnection("Publishers",
               (dbDriverNoPrompt   dbRunAsync), 
               FALSE,
               _T("ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"));
// Wait a few seconds...
// If the connection has not been made, quit.
if (conMain.StillExecuting())
   conMain.Cancel();
else
   {      // Use the Connection object conMain.
   ... 
   conMain.Close();
   }
wrkMain.Close();