Big memory problem 
Author Message
 Big memory problem

I have a very critical problem. I am reading from the database every
quarter second to see if I have messages to send. My problem is that some
meory is never gave back by ADO (I guess) so the memory increases untill
there is not enough virtual memory and the application can not do anything
more.
Here is what I do:

Private Function ReadDB() As String
    Dim StrSql As String
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    '
    On Error GoTo ERROR_HANDLER
    ReadDB = ""
    StrSql = "select top 1 RecId, Data from ThiscoOut;"
    Set cn = CreateObject("ADODB.Connection")
    cn.Open ConnectionString
    cn.CursorLocation = adUseClient
    Set rs = CreateObject("ADODB.Recordset")
    With rs
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .LockType = adLockBatchOptimistic
        .ActiveConnection = cn
        .Open StrSql
    End With
    ' rs.ActiveConnection. '= Nothing
    cn.Close
    Set cn = Nothing
    If Not rs.EOF Then
        ReadDB = rs.Fields("Data").Value
        StrSql = "delete from ThiscoOut where RecId='" &
rs.Fields("RecId").Value & "';"
        rs.Close
        Set rs = Nothing
        Set cn = CreateObject("ADODB.Connection")
        cn.Open ConnectionString
        cn.CursorLocation = adUseClient
        cn.Execute StrSql, adExecuteNoRecords
        cn.Close
        Set cn = Nothing
    Else
        rs.Close
        Set rs = Nothing
    End If
    Exit Function
ERROR_HANDLER:
    LogError StrSql
    Resume Next
End Function

I've been trying to use a command instead but it's worth. I don't know what
to do anymore.
PLEASE HELP.
Kind regards.



Fri, 19 Dec 2003 16:35:23 GMT  
 Big memory problem
Ty having a global connection and recordset which you set using your ReadDB
function.  Have a form or code-based timer that runs every quarter second,
and in the Timer event for that timer, call recordset.requery.  This will
update the recordset which is by then already in memory, and you can check
for any changes in it then, without cleaning up and re-creating each time.

You could also try delaring the connection as "Withevents" of you're using
ADO 2.0+, and react to any changes made to that connection, but you might
need to look at this further, as I've not got it working quite right yet.

Hope this helps...

NB.


Quote:
> I have a very critical problem. I am reading from the database every
> quarter second to see if I have messages to send. My problem is that some
> meory is never gave back by ADO (I guess) so the memory increases untill
> there is not enough virtual memory and the application can not do anything
> more.
> Here is what I do:

> Private Function ReadDB() As String
>     Dim StrSql As String
>     Dim cn As ADODB.Connection
>     Dim rs As ADODB.Recordset
>     '
>     On Error GoTo ERROR_HANDLER
>     ReadDB = ""
>     StrSql = "select top 1 RecId, Data from ThiscoOut;"
>     Set cn = CreateObject("ADODB.Connection")
>     cn.Open ConnectionString
>     cn.CursorLocation = adUseClient
>     Set rs = CreateObject("ADODB.Recordset")
>     With rs
>         .CursorLocation = adUseClient
>         .CursorType = adOpenStatic
>         .LockType = adLockBatchOptimistic
>         .ActiveConnection = cn
>         .Open StrSql
>     End With
>     ' rs.ActiveConnection. '= Nothing
>     cn.Close
>     Set cn = Nothing
>     If Not rs.EOF Then
>         ReadDB = rs.Fields("Data").Value
>         StrSql = "delete from ThiscoOut where RecId='" &
> rs.Fields("RecId").Value & "';"
>         rs.Close
>         Set rs = Nothing
>         Set cn = CreateObject("ADODB.Connection")
>         cn.Open ConnectionString
>         cn.CursorLocation = adUseClient
>         cn.Execute StrSql, adExecuteNoRecords
>         cn.Close
>         Set cn = Nothing
>     Else
>         rs.Close
>         Set rs = Nothing
>     End If
>     Exit Function
> ERROR_HANDLER:
>     LogError StrSql
>     Resume Next
> End Function

> I've been trying to use a command instead but it's worth. I don't know
what
> to do anymore.
> PLEASE HELP.
> Kind regards.



Fri, 19 Dec 2003 19:10:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Re. BIG BIG problem

2. BIG BIG Problem

3. Need big help for big problem

4. Memory management and big array in PowerBASIC or QuickBASIC : Help

5. Not enough memory - too big code

6. ADO, Jet - Memory and big database

7. Out of memory compiling big VB4 16bit App

8. Memory issues with big inserts

9. OLE Automation Problems - MEMORY HOG (Memory Leak?)

10. Big Versions, Big Words

11. How big is too big?

12. How big is a big vb-exe

 

 
Powered by phpBB® Forum Software