?
Solved

Use a record set without keeping connection open?

Posted on 2002-05-22
5
Medium Priority
?
158 Views
Last Modified: 2010-05-02
First of all I'm new to VB and programming in general so I may not be explaining my problem correctly.
I've created a VB 6 app. that will be used to deliver quizzes to highschool students. The questions and answers are in an Access 2000 database table with each record being one question and it's multiplechoice answers eg.
QuestionNumber, Question, RightAnswer, WrongAnswr1....
Using ADO I create a recordset of the table and "Dowhile not rs.EOF" present the user with one question at a time. The problem is that the connection to the database must (or does it?) remain open throughout the quiz so the number of concurrent users is very limited without an SQL server.
How can I open the connection, create the recordset, close the connection and then cycle through the questions.

Is this clear?
0
Comment
Question by:sooketech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Bahnass earned 300 total points
ID: 7027691
just

set RecSet.connection =Nothing

U can Use Ur Disconnected Recordset for reading but No    UPDATE
I think this is fair for Ur app
0
 
LVL 1

Author Comment

by:sooketech
ID: 7027815
Could you give a little more info on exactly how I do that? Here's the Code I'm using to create the recordset.
---------------------------------------
'CHOOSE THE TABLE AND FIELDS WE'LL BE USING FOR THE QUIZ
    strSQL = "SELECT fldQuestion,fldCorrect,fldWrong1,fldWrong2,fldWrong3"
    strSQL = strSQL & "FROM tblQuiz"
    strSQL = strSQL & intQuizNumber
'CREATE THE RECORD SET
    OpenConnection 'FUNCTION (SEE BELOW)

    Set rsQuiz = New ADODB.Recordset
    With rsQuiz
        .ActiveConnection = cnQuizzer
        .CursorLocation = adUseClient
        .CursorType = adOpenForwardOnly
        .Source = strSQL
        .Open
    End With
'I NEED TO CLOSE THE CONNECTION BEFORE HERE
Do While Not rsQuiz.EOF
----------------------------------------

Public Sub OpenConnection()
    'establish the connection object
    Set cnQuizzer = New ADODB.Connection
    With cnQuizzer
        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Quizzer.mdb;Persist Security Info=False"
        .Open
    End With
End Sub
0
 
LVL 20

Expert Comment

by:hes
ID: 7027833
As Bahnass said change your code from



   Set rsQuiz = New ADODB.Recordset
   With rsQuiz
       .ActiveConnection = cnQuizzer
       .CursorLocation = adUseClient
       .CursorType = adOpenForwardOnly
       .Source = strSQL
       .Open
   End With
'I NEED TO CLOSE THE CONNECTION BEFORE HERE
Do While Not rsQuiz.EOF

TO:



   Set rsQuiz = New ADODB.Recordset
   With rsQuiz
       .ActiveConnection = cnQuizzer
       .CursorLocation = adUseClient
       .CursorType = adOpenForwardOnly
       .Source = strSQL
       .Open
   End With
cnQuizzer.Close
Set cnQuizzer = Nothing
Do While Not rsQuiz.EOF
0
 
LVL 1

Author Comment

by:sooketech
ID: 7028107
Thanks Bahnass, after some playing around I got it to work. Thanks also to hes.
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 7029056
Thanks Both

Sorry 4 not being here


Grade B Accepted
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 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