Solved

Database recordset error

Posted on 2004-04-28
7
775 Views
Last Modified: 2013-11-26
Below is a function I am using to populate two Data controls recordset.
-----------------------------------------------------
Private Function populateCombos()

Dim sql1 As String
Dim sql2 As String

On Error GoTo ErrorHandler

    sql1 = "execute proc1"
    sql2 = "execute proc2"
   
    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If
   
    Exit Function

ErrorHandler:
    populateCombos = False

End Function
-------------------------------------------------

However, the second recordset open fails. The error msg says that the "Connection is busy with results for another htsmt"

I found somewhere that says this is due to the first recordset is still being worked on. However, I used this format of code before without problems. The difference this time is that I have not linked a grid to the Data Control.

I want to avoid opening multiple connections as I do not require ability to write.

Many thanks
0
Comment
Question by:2000bug
7 Comments
 
LVL 9

Expert Comment

by:p_sie
ID: 10937858
MAybe place a doEvents between the to database-calls?

 Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
 DoEvents
 Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 10937878
You may want to check the state bvefore


ie

dbMain.state


Constant Description
adStateClosed       Default. Indicates that the object is closed.
adStateOpen          Indicates that the object is open.
adStateConnecting Indicates that the Recordset object is connecting.
adStateExecuting    Indicates that the Recordset object is executing a command.
adStateFetching      Indicates that the rows of the Recordset object are being fetched.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10937974
to clarify what EDDYKT suggested, change your code like this (from this:

    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)
        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)
        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If

to:

    If ConnectToDB Then
        Set dat1.Recordset = dbMain.OpenRecordset(sql1, dbOpenDynaset, dbSQLPassThrough)

        ' wait until the first recordset is filled, before proceeding to second recordset
        Do While dbMain.State = adStateFetching
            DoEvents
        Loop

        Set dat2.Recordset = dbMain.OpenRecordset(sql2, dbOpenDynaset, dbSQLPassThrough)

        ' wait until the sedond recordset is filled, before proceeding
        Do While dbMain.State = adStateFetching
            DoEvents
        Loop

        populateCombos = True
    Else
        msgbox "connection to database failed"
        populateCombos = False
    End If

the second 'wait loop' is possible un-necessary, but it is better to be safe than sorry.

AW
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:2000bug
ID: 10938000
theres no dbMain.state

dbMain is a Database object
0
 

Author Comment

by:2000bug
ID: 10938199
I have resolved the issue.

The data was not 'flushed' out of the recordset. That is why it worked when I had a grid attached to the Data Control as it did that for me.

I simply had to do a MoveFirst MoveLast manually.

Thanks for your comments.

I shall request for a delete.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 10971798
Closed, 250 points refunded.
PashaMod
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now