Visual Basic Concepts

RDO Collection Management

RDO uses a collection to manage each of the RDO objects except the RDO engine itself. Because Visual Basic version 6.0 now supports the creation of some stand-alone objects like rdoConnection and rdoQuery objects, not all objects are automatically appended to their parent collection — but in most cases, this is done automatically. Stand-alone rdoConnection and rdoQuery objects can be appended to their parent collection using the Add method and can be removed from the collection using the Remove method.

The rdoParameters collection is automatically created when using the CreateQuery method. However, if the ODBC interface cannot parse the SQL syntax for any reason, this collection used to manage a query's parameters is not created. Therefore, any reference to the rdoParameters collection will result in a trappable error unless RDO successfully parses the SQL parameter query as specified in the SQL property of the rdoQuery object. This collection is also not populated if the ODBC data source driver does not support the SQLNumParams function or if this function returns an error.

The following table lists the collections managed by RDO:

RDO collection Description
rdoErrors Contains all stored rdoError objects which pertain to a single operation involving Remote Data Objects (RDO).
rdoEnvironments Contains all active rdoEnvironment objects of the rdoEngine object. rdoEnvironments(0) is created automatically.
rdoConnections Contains all rdoConnection objects opened or created in an rdoEnvironment object, or allocated and appended to the rdoConnections collection using the Add method.
rdoTables Contains all stored rdoTable objects in a database.
rdoResultsets Contains all open rdoResultset objects in an rdoConnection.
rdoColumns Contains all rdoColumn objects of an rdoResultset or rdoTable object.
rdoQueries Contains rdoQuery objects that have been added to the rdoQueries collection either automatically via the CreateQuery method, or with the Add method.
rdoParameters Contains all the rdoParameter objects of an rdoQuery object once the SQL statement is successfully parsed. Contains an rdoParameter object for each marked parameter in the query.

RDO 1.0 Collections

RDO 1.0 objects and their collections are managed differently than RDO 2.0 objects and collections. When you open or create a new RDO 1.0 object, it is automatically appended to the collection associated with those objects, even when you set an existing variable to the newly created object.

For example, the following RDO 1.0 code creates two independent rdoConnection objects:

Dim Cn as rdoConnection
Set Cn = rdoEnvironments(0).OpenConnection(  _ 
      dsname:="MyDSN", _ 
      prompt:=rdDriverNoPrompt,  _ 
      connect:="UID=;PWD=;")
Set Cn = rdoEnvironments(0).OpenConnection(  _ 
      dsname:="MyOtherDSN", _ 
      prompt:=rdDriverNoPrompt,  _ 
      connect:="UID=;PWD=;")

After this code is executed, both RDO 1.0 rdoConnection objects are appended as members of the rdoConnections collection. With this behavior in mind, your code must use the Close method on objects that are no longer needed as they are not automatically closed — even when assigned to the same variable. This same behavior applies to rdoResultset objects as well.

RDO 2.0 Collections

In RDO 2.0, setting an existing variable to a newly created object releases or closes the existing RDO object before replacing it with the newly created RDO object. This change makes RDO work more like DAO objects.

When the code shown above is executed in Visual Basic using RDO 2.0, only one rdoConnection object is created: The first rdoConnection object is closed and removed from the rdoConnections collection. If your Visual Basic version 4.0 code explicitly closes RDO connections and rdoResultset objects, you need not be concerned with backward compatibility. However, if you depend on these objects to be maintained, then you must assign new RDO objects to new variables or the original object will be lost.