Solved

rollback not working.

Posted on 2004-08-20
2
242 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

11 Experts available now in Live!

Get 1:1 Help Now