PRB: Dynaset Loses Contents After Transaction Rollback

Last reviewed: June 21, 1995
Article ID: Q109995
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 3.0

SYMPTOMS

If a Dynaset is used in a transaction, records in the Dynaset appear to be lost when the transaction is rolled back.

CAUSE

This is by design. A Dynaset is populated one record at a time, so the RollBack operation removes all the records added during the transaction. After the RollBack operation, the Dynaset contains the single record that was there before BeginTrans began the transaction.

RESOLUTION

Create the complete Dynaset before starting the transaction. For example, replace the code shown in step 3 of the More Information section with this code:

   Sub Command1_Click ()
      Dim db As database
      Dim ds As Dynaset
      Set db = OpenDatabase("Biblio.mdb")
      Set ds = db.CreateDynaset("authors")

      ' Create the complete Dynaset before starting the transaction.
      ds.MoveLast
      ds.MoveFirst

      ' Populate the listbox with the contents of the Dynaset.
      BeginTrans
         While Not ds.EOF
            list1.AddItem ds(0)
            ds.MoveNext
         Wend
      Rollback

      ds.MoveFirst
      While Not ds.EOF
         list2.AddItem ds(0)
         ds.MoveNext
      Wend
   End Sub

STATUS

This behaviour is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add two list boxes (List1 and List2) and a command button (Command1) to Form1.

  3. Add the following code to the Command1_Click event:

       Sub Command1_Click ()
          Dim db As database
          Dim ds As Dynaset
          Set db = OpenDatabase("Biblio.mdb")
          Set ds = db.CreateDynaset("authors")
    
          'This code populates the listbox with the contents of the Dynaset.
          BeginTrans
             While Not ds.EOF
                list1.AddItem ds(0)
                ds.MoveNext
             Wend
          Rollback
    
          'This code reports only one record in the dynaset.
          ds.MoveFirst
          While Not ds.EOF
             list2.AddItem ds(0)
             ds.MoveNext
          Wend
       End Sub
    
    

  4. Run the application or press the F5 key. Click the Command1 button. The first list box is populated correctly but the second contains only a single record.


Additional reference words: 3.00
KBCategory: kbprg kbcode kbprb
KBSubCategory: APrgDataOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.