Solved

Use a record set without keeping connection open?

Posted on 2002-05-22
5
153 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
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Bahnass earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Bahnass, after some playing around I got it to work. Thanks also to hes.
0
 
LVL 3

Expert Comment

by:Bahnass
Comment Utility
Thanks Both

Sorry 4 not being here


Grade B Accepted
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

728 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

10 Experts available now in Live!

Get 1:1 Help Now