Solved

rollback not working.

Posted on 2004-08-20
2
245 Views
Last Modified: 2008-02-01
hello experts, i am trying to run create table, insert records and delete records in a table made in Oracle.
but once i have delted few records thru this program, i am not able to get them back by running RollBack command at sql prompt of Oracle 8. i m using connection string to connect to oracle. other things are working fine. I am providing the code below. please help. i wish to get the records back by using Rollback.
the code follows :

Option Explicit
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim sql As String, i As Integer

Private Sub Form_Load()
    Set con = New ADODB.Connection
    Set rs = New ADODB.Recordset
    Set cmd = New ADODB.Command
    con.ConnectionString = "Provider=MSDAORA.1;User ID=scott/tiger;Persist Security Info=False"

    con.Open
    cmd.ActiveConnection = con
    i =1
End Sub

Private Sub cmdCreateTable_Click()
 cmd.ActiveConnection = con
cmd.CommandText="Create table tempp(rno number")
    cmd.Execute
    Print "Table Created !"
End Sub

Private Sub cmdInsert_Click()
    sql = "Insert into tempp values(1)
    cmd.CommandText = sql
    cmd.Execute    

    sql = "Insert into tempp values(2)
    cmd.CommandText = sql
    cmd.Execute    

    sql = "Insert into tempp values(3)
    cmd.CommandText = sql
    cmd.Execute    
End Sub

Private Sub cmd_delete_Click()
' delete few records
cmd.CommandText = "Delete tempp where rno>1"
    cmd.Execute
    Print "Records  Deleted !"
''''''''' Here is the Problem  ''''''''''
End Sub

The records deleted thru Vb cant be recalled even after rollback is issued from SQL.
0
Comment
Question by:astudent
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 11850174
ROLLBACK (and COMMIT) are related to the session, not to the user or even the database.
So IF you want to perform a ROLLBACK, you need to do this using the connection in the program (thus in the program itself), which is enabled only by starting a explicit TRANSACTION in the application itself.
The ROLLBACK will rollback all the insert/delete/update since the last BEGIN TRANSACTION, not only the last action.

CHeers
0
 
LVL 8

Accepted Solution

by:
SNilsson earned 100 total points
ID: 11850216
To be able to do a rollback you first need to begin a transaction, like the example below

Private Sub cmd_delete_Click()
   On error goto ErrFix
   con.BeginTrans
   cmd.CommandText = "Delete tempp where rno>1"
   cmd.Execute
   con.CommitTrans
   Print "Records  Deleted !"
   Exit sub
ErrFix:
   con.RollbackTrans
   Print "Transactions Rolled back !"
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Controlling which port to download from 4 71
vb6 programatically bring window to front 8 63
VBA open file from excel cell 4 36
VBA saving file message display 5 56
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now