Solved

rollback not working.

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…

809 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