Visual Basic Concepts
RDO 2.0 supports far more asynchronous operations than supported by RDO 1.0. For example, all of the following operations now permit use of the rdAsyncEnable option:
To better support asynchronous operations, RDO now supports two properties that can be polled to test for asynchronous operation completion:
In addition, RDO also exposes a number of events on the rdoConnection object that are fired as the operations are completed:
When your application submits a query to a remote server, you often have no way of determining how much time will pass before the first row is returned. Because of the way SQL Server and some other servers process result sets, your application might not be passed the results until:
A typical query can take from milliseconds to hours or even days to complete — or it might never complete if the server or your workstation runs out of resources before the server completes the job. In some cases, the remote server begins to pass rows back fairly quickly, at which time RDO begins to populate your rdoResultset based on the type of cursor you choose. However, the remote server often stops working until your application begins to access those rows by moving forward in the result set. In many cases, rows or entire pages of data are locked on the server until the query is complete, which can only occur when you populate the last row of the rdoResultset object by using one of the Move methods, like MoveLast, or simply referencing the RowCount property.
Because of this uncertainty, it makes sense to prevent your application from blocking while the query is taking place and to ensure your application populates the result sets as quickly as possible. Unless you enable asynchronous operation by setting the rdAsyncEnable option with the OpenResultset method, your application will block until the first row of the result set is returned by the ODBC driver.
In addition to enabling the rdAsyncEnable option, you can also code an event handler to trap the QueryComplete event that fires when the query completes.
When you use the OpenResultset method with the rdAsyncEnable option, RDO returns control to your application immediately. At this point, the rdoResultset object is instantiated, but its rowset might not be ready to use — and won't be until the remote server begins to pass rows back. As an indication of this state, the StillExecuting property will return True until the first row is available. Once StillExecuting returns False, the rdoResultset data is available and the QueryComplete event is fired.
When using the asynchronous operation option, your application regains control while the remote server is busy working on your query or simply populating your result set. Since this operation might take some time to complete, you need to decide what your applications should do in the meantime. The following suggestions can help you choose a viable strategy:
This drawing illustrates how to setup an asynchronous file import routine.
Figure 11.2 Running overlapping procedures while waiting for an asynchronous operation
This technique leverages both the thread used to execute your query on the remote server and the thread available on the workstation.
As long as the asynchronous operation is still executing, you cannot reference the rdoResultset, rdoQuery, or rdoConnection object being processed — except for the properties and methods listed in the following table.
Valid Properties and Methods During Asynchronous Operations
Remote Data Object | Valid Properties and Methods |
rdoConnection | StillConnecting property; Cancel, Close methods |
rdoQuery | StillExecuting property; Cancel, Close methods |
rdoResultset | StillExecuting property; Cancel, Close methods |
If you decide that you have waited long enough for an asynchronous operation to complete, you can choose to tell the remote processor to abandon the operation by using either the Cancel or Close methods.
Using one of these methods is not always prudent in cases where you have submitted complex multistatement or broad-scope update operations because database integrity could be compromised.