HOWTO: Implement Visual Basic COM Objects Returning Recordsets

ID: Q224424


The information in this article applies to:
  • Active Server Pages
  • ActiveX Data Objects (ADO), versions 1.5, 2.0, 2.1 SP2
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Internet Information Server versions 4.0, 5.0


SUMMARY

This article describes, by example, how to implement a Visual Basic Component Object Model (COM) Object that returns a recordset to Active Server Pages (ASP).

Implementing this incorrectly can result in memory leaks or one of the following errors:

The operation requested by the application is not allowed if the object is closed.
-or-
Type Mismatch
-or-
error 'ASP 0115' - A trappable error occured in an external object


MORE INFORMATION

Use the following steps to implement a method that returns a recordset from a Visual Basic COM Object to Active Server Pages:

  1. Create a Visual Basic ActiveX DLL project called PassRsPrj.


  2. Add a class module and change its name to PassRsObj.


  3. Implement the following method:


  4. 
    Public Function TestRs() as ADODB.Recordset
        Dim rsObj As New ADODB.Recordset
        Dim cnObj As New ADODB.Connection    
          
        cnObj.Open("DSN=pubs;uid=sa;pwd=")
        
        Set rsObj.ActiveConnection = cnObj
    
        'To use disconnected Recordset you must use client side cursors
        rsObj.CursorLocation = adUseClient
    
        rsObj.Open "select * from authors"
        
        'Use a disconnected recordset to efficiently use connection pooling
        Set rsObj.ActiveConnection = Nothing
    
        'Clone the recordset.
         'NOTE You can only clone a recordset that supports bookmarks 
         Set Testrs = rsObj.Clone 
        
        'Clean up Resource
        rsObj.Close
        cnObj.Close
        
        Set rsObj = Nothing
        Set cnObj = Nothing
        
    End Function 
  5. Create an ASP page with the following code:


  6. 
    <%
    Dim rsTest, oTestPassRs
    
    Set oTestPassRs = Server.CreateObject("PassRsPrj.PassRsObj")
    Set rsTest = oTestPassRs.TestRs()
    
    Do 
       Response.Write ( "Value in Record = " & rsTest(1) & "<BR>" )
       rsTest.MoveNext
    Loop until rsTest.EOF
    
    rsTest.Close
    Set rsTest = Nothing
    Set oTestPassRs = Nothing
    %> 

Additional query words:

Keywords : kberrmsg kbADO kbASP kbCOMt kbDatabase kbVBp kbVBp500 kbVBp600 kbGrpASP kbGrpVBDB kbGrpMDAC kbDSupport kbADO210sp2 kbMDAC210SP2 kbiis400 kbiis500
Version : WINDOWS:1.5,2.0,2.1 SP2,5.0,6.0; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.