Microsoft KB Archive/106493: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 71: | Line 71: | ||
To avoid the problem entirely, always do a BeginTrans before attempting a Rollback.<br /> | To avoid the problem entirely, always do a BeginTrans before attempting a Rollback.<br /> | ||
<br /> | <br /> | ||
You can work around the | 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. | ||
</div> | </div> | ||
Line 93: | Line 93: | ||
Dim db As database | Dim db As database | ||
Dim ds As dynaset | Dim ds As dynaset | ||
Set db = OpenDatabase( | Set db = OpenDatabase("c:\vb3\biblio.mdb") | ||
Set ds = db.CreateDynaset( | Set ds = db.CreateDynaset("authors") | ||
On Error Resume Next | On Error Resume Next | ||
' WORKAROUND: Add the following statement here: BeginTrans | ' WORKAROUND: Add the following statement here: BeginTrans |
Latest revision as of 10:08, 20 July 2020
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:
clicking a data control or executing a database method may result in this error:
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:
Additional query words: 3.00
Keywords: kbprb KB106493