New topic: 

Using ADODB recordsets does not destroy objects

<http://forums.realsoftware.com/viewtopic.php?t=43898>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        pssrb          Post subject: Using ADODB recordsets does not 
destroy objectsPosted: Sun May 06, 2012 2:16 pm                         
Joined: Sat Aug 30, 2008 2:20 pm
Posts: 87
Location: Barcelona, Spain                I need to use ADODB recordsets with a 
Microsoft Access database, but I see that OLEObjects are not destroyed upon 
exiting my method

Beginning with the "ADO example" in the examples folder of RB, add a new button 
and name it "COUNT". Insert this code in that button

Dim iM, iK, iCnt As Integer
Dim sTx As String

iCnt = 0
sTx = ""
iM = Runtime.ObjectCount
For iK = 0 to iM - 1
  If  Runtime.ObjectClass(iK) = "OLEObject" Then
  iCnt = iCnt + 1
  sTx = sTx + Str(Runtime.ObjectID(iK)) + ", "
  End If
Next
MsgBox "OLEObjects: " + CStr(iCnt) + ": " + sTx


Then, push the "Test" button already present in this sample, and then, this 
"COUNT" button. You will see that the count is 0.

But if you want to use an ADODB recordset for navigating forward and backward, 
the code in the "TEST" button can not be used, instead I use the following, 
that you can put in another button named "RECORDS"

Dim cn as new OLEObject( "ADODB.Connection" )
Dim rs as OLEObject
Dim sConn as string

' OPEN CONNECTION------------------------
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn = sConn + "Data Source=C:\Program Files\Real Software\Real Studio 
2011r4\Example Projects\Windows OS specific\Win32 ADO Example\ADODEMO.MDB;"
cn.Open( sConn )

' OPEN RECORDSET-------------------------
sTx = "SELECT * FROM Authors"
rs = New OLEObject("ADODB.Recordset")
rs.Open sTx, cn, 1, 1, 1  ' cn: Connection, 1: adOpenKeyset, 1: adLocReadonly, 
1: adCmdText

' USE THE RECORDSET----------------------
rs.movenext
rs.moveprevious

exception err as OLEException
msgbox err.message


If you push the button "RECORDS", and then the button "COUNT", you will see 
that one OLEObject (that of the recordset) is not destroyed.

What code must I use to get my required functionality and have the objects 
destroyed ?   
                             Top                Jym          Post subject: Re: 
Using ADODB recordsets does not destroy objectsPosted: Sun May 06, 2012 2:47 pm 
                        
Joined: Sat Oct 01, 2005 5:19 pm
Posts: 3027                Have you tried cn.Close ?   
                             Top                pssrb          Post subject: 
Re: Using ADODB recordsets does not destroy objectsPosted: Sun May 06, 2012 
5:25 pm                         
Joined: Sat Aug 30, 2008 2:20 pm
Posts: 87
Location: Barcelona, Spain                Yes, at the end of the code posted, I 
also tried with the following with the same results
rs.Close
rs = Nil
cn.Close
cn = Nil
   
                             Top                pierce          Post subject: 
Re: Using ADODB recordsets does not destroy objectsPosted: Sun May 06, 2012 
6:46 pm                         
Joined: Mon Jun 01, 2009 7:22 pm
Posts: 6
Location: Auckland, New Zealand                This may help?. In all my 
VBA/VB6 code is use the following:

rs.Close
rs = Nothing
cn.Close
cn = Nothing

Note that I use "Nothing" not "Nil".   
                             Top                pssrb          Post subject: 
Re: Using ADODB recordsets does not destroy objectsPosted: Mon May 07, 2012 
1:23 am                         
Joined: Sat Aug 30, 2008 2:20 pm
Posts: 87
Location: Barcelona, Spain                This does not help, the verb Nothing 
does not exist in RB, even if you try with "Nothing", it tells that it is of an 
incorrect type.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to