How To Implement Visual Basic COM Objects Returning Recordsets
Symptoms
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
Resolution
Use the following steps to implement a method that returns a recordset from a Visual Basic COM Object to Active Server Pages: Create a Visual Basic ActiveX DLL project called PassRsPrj.Add a class module and change its name to PassRsObj.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.RecordsetDim rsObj As ADODB.RecordsetDim cnObj As ADODB.Connectionset rsObj = New ADODB.Recordsetset cnObj = New ADODB.Connection’Open connection to databasecnObj.Open(“DSN=pubs;uid=<username>;pwd=<strong password>”)’To use disconnected Recordset you must use client side cursorsrsObj.CursorLocation = adUseClientrsObj.Open “select * from authors”, cnObj, adOpenKeyset, _adLockOptimistic, adCmdText’Disconnected recordsetSet rsObj.ActiveConnection = Nothing’Set return valueSet Testrs = rsObj’Clean up resourcescnObj.CloseSet cnObj = NothingEnd Function Create an ASP page with the following code:
<%Dim rsTest, oTestPassRsSet oTestPassRs = Server.CreateObject(“PassRsPrj.PassRsObj”)Set rsTest = oTestPassRs.TestRs()DoResponse.Write ( “Value in Record = ” & rsTest(1) & “<BR>” )rsTest.MoveNextLoop until rsTest.EOFrsTest.CloseSet rsTest = NothingSet oTestPassRs = Nothing%>

Leave a Reply