Solved

Database recordset error

Posted on 2004-04-28
7
772 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

24 Experts available now in Live!

Get 1:1 Help Now