Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

rollback not working.

Posted on 2004-08-20
2
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

705 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