To store a SQL-DMO object returned from another object, you must declare an object variable of the appropriate SQL-DMO object type.
Declare an object variable of a specific SQL-DMO object type (if your version of Visual Basic supports it). This uses early, vtable-binding or dispID-binding, depending on your version of Visual Basic, and requires that the SQL-DMO type library be included in your Visual Basic project. For example:
Dim oDatabase As SQLOLE.Database
Or you can declare an object variable of the generic Object type. This uses late-binding, and does not require the SQL-DMO type library. For example:
Dim oDatabase As Object
Then assign a returned SQL-DMO object (from a collection, an object property, or a method return value) to the declared object variable. For example:
Set oDatabase = oSQLServer.Databases("pubs")
Note that you can assign a returned SQL-DMO object to an object variable declared using the New keyword (if your version of Visual Basic supports it). Visual Basic will automatically release an object created by the New keyword before assigning a new object to the variable. However, if you are declaring an object variable just to hold a returned SQL-DMO object, do not use the New keyword. The overhead of creating and releasing the object is unnecessary.
Declare an object variable of the appropriate SQL-DMO "pointer to an object" type. All SQL-DMO object types begin with LPSQLOLE.
For example, to declare a new Database object variable and assign the pubs database object (part of the SQLServer.Databases collection) to the new object variable:
LPSQLOLEDATABASE pDatabase = NULL; hr = pSQLServer->GetDatabaseByName (TEXT("pubs"), (LPVOID*)&pDatabase);