Microsoft KB Archive/106493

From BetaArchive Wiki

Article ID: 106493

Article Last Modified on 1/8/2003



APPLIES TO

  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q106493

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 query words: 3.00

Keywords: kbprb KB106493