PRB: Invalid Database Object after Rollback without BeginTrans
ID: Q106493
|
The information in this article applies to:
-
Microsoft Visual Basic Professional Edition 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
- Start Visual Basic or begin a New Project. Form1 is created by default.
- 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
- Start Visual Basic or begin a New Project. Form1 is created by default.
- 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.
- Add a text box (Text1) to Form1, and give Text1 these properties:
DataSource = Data1
DataField = Au_ID
- 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
- 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
- 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 :
Version :
Platform :
Issue type :