Solved

Use a record set without keeping connection open?

Posted on 2002-05-22
5
157 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 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

717 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