PRB: Invalid Database Object after Rollback without BeginTrans

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

- Professional Edition of Microsoft Visual Basic for Windows,

  version 3.0

SYMPTOMS

After your program gets this error:

   Commit or Rollback without BeginTrans (Err = 3034)

clicking a data control or executing a database method may result in this error:

   Invalid Database Object

CAUSE

You tried to commit or roll back a transaction that you didn't start with a BeginTrans statement.

WORKAROUND

To avoid the problem entirely, always do a BeginTrans before attempting a Rollback.

You can work around the "Invalid Database Object" error by using the Refresh method on the data control. For example, add the statement Data1.Refresh after the Rollback, at the bottom of the Command1_Click procedure shown in the Steps to Reproduce Behavior section below.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior Using Database Object Variables

  1. Start Visual Basic or begin a New Project. Form1 is created by default.

  2. Add a command button (Command1) to Form1. Enter the following code:

       Sub Command1_Click ()
          Dim db As database
          Dim ds As dynaset
          Set db = OpenDatabase("c:\vb3\biblio.mdb")
          Set ds = db.CreateDynaset("authors")
          On Error Resume Next
          ' WORKAROUND: Add the following statement here:   BeginTrans
          Rollback
          Print Error$
          On Error GoTo 0
       End Sub
    
    

Steps to Reproduce Behavior using Text Control Bound to Data Control

  1. Start Visual Basic or begin a New Project. Form1 is created by default.

  2. Add a data control (Data1) to Form1, and give Data1 these properties:

       DatabaseName = C:\VB\BIBLIO.MDB   ' This database shipped with VB
       RecordSource = Authors            ' Use the Authors Table.
    
    

  3. Add a text box (Text1) to Form1, and give Text1 these properties:

    DataSource = Data1 DataField = Au_ID

  4. Add a command button (Command1) to Form1. Enter the following code:

       Sub Command1_Click ()
          On Error Resume Next
          Rollback
          Print Error$
          ' WORKAROUND is to add the following statement here:  Data1.Refresh
       End Sub
    
    

  5. Start the program by pressing the F5 key. Click the Command1 button. The following correct error is trapped by the error handler:

    Commit or Rollback without BeginTrans

  6. Now click the data control arrow to move to the next record. This causes the following error:

    Invalid Database Object


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.