Microsoft Knowledge Base Email Alertz

(224424) - 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...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 224424 - Last Review: July 1, 2004 - Revision: 4.2

How To Implement Visual Basic COM Objects Returning Recordsets

This article was previously published under Q224424

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:

    Note You must change the UID and the PWD values to the ones that are used on your system.
    Public Function TestRs() as ADODB.Recordset
           Dim rsObj As ADODB.Recordset
           Dim cnObj As ADODB.Connection    
    
           set rsObj = New ADODB.Recordset         
           set cnObj = New ADODB.Connection
    
           'Open connection to database
           cnObj.Open("DSN=pubs;uid=<username>;pwd=<strong password>")
           
           'To use disconnected Recordset you must use client side cursors
           rsObj.CursorLocation = adUseClient
    
           rsObj.Open "select * from authors", cnObj, adOpenKeyset, _
              adLockOptimistic, adCmdText
           
           'Disconnected recordset
           Set rsObj.ActiveConnection = Nothing
    
           'Set return value
           Set Testrs = rsObj
           
           'Clean up resources
           cnObj.Close
           Set cnObj = Nothing
           
       End Function
    					
  4. Create an ASP page with the following code:
    <%
       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
       %>
    					

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
244012  (http://kbalertz.com/Feedback.aspx?kbNumber=244012/ ) INFO: Type Mismatch Errors When You Pass Parameters from ASP to a Visual Basic Component

APPLIES TO
  • Microsoft Active Server Pages 4.0
  • Microsoft ActiveX Data Objects 1.5
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Services 5.0
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
Keywords: 
kbcodesnippet kbdatabase kberrmsg kbhowto KB224424
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate