Try Using scope As new TransactionScope() Using con As New OracleConnection(接続文字列) con.Open() Dim cmd = con.CreateCommand() cmd.CommandText = 更新SQL cmd.ExecuteNonQuery() con.Close() End Using scope.Complete() 'これが CommitTrans に相当します End Using Catch ex As Exception '例外処理などにより、Complete せずに破棄されると、自動的に Rollback されます Debug.WriteLine(ex.ToString()) End Try
Using con As New OracleConnection(接続文字列) '実際は接続失敗時の Try~Catch も必要 con.Open() Using txn As OracleTransaction = con.BeginTransaction(IsolationLevel.ReadCommitted) Try Dim cmd = con.CreateCommand() cmd.CommandText = 更新SQL cmd.ExecuteNonQuery() txn.Commit() 'これが CommitTrans 相当 Catch ex As Exception Debug.WriteLine(ex.ToString()) txn.Rollback() 'これが Rollback 相当 End Try End Using End Using