オラクルで ADO.NET トランザクション
ADO.NET トランザクションの作成は非常に簡単です。標準的な ADO.NET のコーディングモデルとの相違点は、
トランザクションコンテキストに対してコマンドをラップする必要があるということだけです。
利点
- 作成が簡単です。
- データベース トランザクションとほぼ同じ処理速度です。
- トランザクションで複数のデータベース呼び出しを行えます。
ソース記述例[VB.NET]
Dim conn As OracleConnection
Dim tx As OracleTransaction
Try
conn = New OracleConnection("user id=test;data source=TEST;password=""test""")
conn.Open()
tx = conn.BeginTransaction(IsolationLevel.Serializable)
Dim deleteSql As String = "DELETE FROM TEST"
Dim command As New OracleCommand(deleteSql, conn, tx)
command.ExecuteNonQuery()
Dim insertSql As String = "INSERT INTO TEST VALUES('')"
command.CommandText = insertSql
command.ExecuteNonQuery()
command.Dispose()
tx.Commit()
Catch ex As Exception
tx.Rollback()
Throw ex
Finally
tx.Dispose()
conn.Close()
End Try
|