2
我創建了一個Oracle事務,嘗試將一些數據保存在兩個表中,並且在第二個過程中導致錯誤以調用回滾並檢查它是否有效。Oracle事務回滾不起作用
第一個程序使用sys.dbms_scheduler.create_job
在USER_SCHEDULER_JOBS中創建作業。
Private Function CreateJobDef() As Integer
Try
Cursor.Current = Cursors.WaitCursor
conn = New OracleConnection
conn.ConnectionString = gApp.ConnectString
conn.Open()
Dim cmd As OracleCommand = conn.CreateCommand()
Dim oraclTrans As OracleTransaction
oraclTrans = conn.BeginTransaction()
cmd.Transaction = oraclTrans
Try
cmd.CommandText = "TEST.CREATE_JOB_SCHEDULE"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Clear()
OracleCommandBuilder.DeriveParameters(cmd)
cmd.Parameters("in_job_name").Value = txtName.Text
cmd.Parameters("in_schedule_name").Value = cboSchedule.SelectedValue
cmd.Parameters("in_enabled").Value = If(chkEnabled.Checked, 1, 0)
cmd.Parameters("in_comments").Value = txtComments.Text
cmd.ExecuteNonQuery()
'Everything is OK
'-----------------------------------------------
cmd.CommandText = "TEST.Update_Job_Def"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Clear()
OracleCommandBuilder.DeriveParameters(cmd)
cmd.Parameters("in_job_id").Value = "WQwqwq" 'I set this to a string to cause an error in the second procedure to check the rollback
cmd.Parameters("in_job_name").Value = txtName.Text
cmd.Parameters("in_job_type").Value = cboType.SelectedItem
cmd.Parameters("in_report_nav_id").Value = cboReport.SelectedValue
cmd.Parameters("in_mail_address_to").Value = txtMailTo.Text
cmd.ExecuteNonQuery()
oraclTrans.Commit()
Catch ex As OracleException
Msgbox(ex.ToString)
oraclTrans.Rollback()
Catch ex As Exception
Msgbox(ex.ToString)
oraclTrans.Rollback()
Finally
conn.Close()
If conn IsNot Nothing Then conn.Dispose()
If cmd IsNot Nothing Then cmd.Dispose()
End Try
Catch ex As OracleException
Msgbox(ex.ToString)
Catch ex As Exception
Msgbox(ex.ToString)
Finally
Cursor.Current = Cursors.Default
End Try
End Function
問題是第一個過程是創建一個新的Job,儘管我在第二個過程中導致了一個錯誤,並且調用了回滾。 任何想法?
感謝
這太糟糕了。放棄新創建的計劃作業而不是回滾是否「正確」? – Nianios
是的,就是這樣做的。 –
非常感謝 – Nianios