Imports System.Data
Imports System.Data.Common
'*******************************************************************
'* Page/Class Name:XPTransaction.vb
'* Title:数据库事务处理类
'* Description:简单三层结构数据库事务处理类
'* Copyright:
'* Company:
'* @author:Owen,Yuan
'* Create Date:2010/3/22 10:44:20
'* Last Modifier:
'* Last Modify Date:
'*******************************************************************
Public Class XPTransaction
Implements IDisposable
Private conn As DbConnection
Private dbTrans As DbTransaction
Public Property DbConnection() As DbConnection
Get
Return Me.conn
End Get
Set(ByVal Value As DbConnection)
Me.conn = Value
End Set
End Property
Public Property DbTransact() As DbTransaction
Get
Return Me.dbTrans
End Get
Set(ByVal Value As DbTransaction)
Me.dbTrans = Value
End Set
End Property
Public Sub New()
conn = XPDBHelper.CreateConnection()
conn.Open()
dbTrans = conn.BeginTransaction()
End Sub
Public Sub New(ByVal connectionString As String)
conn = XPDBHelper.CreateConnection(connectionString)
conn.Open()
dbTrans = conn.BeginTransaction()
End Sub
Public Sub Commit()
dbTrans.Commit()
Me.Colse()
End Sub
Public Sub RollBack()
dbTrans.Rollback()
Me.Colse()
End Sub
Public Sub Colse()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Sub
Private disposedValue As Boolean = False ' 检测冗余的调用
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
conn.Close()
' TODO: 释放其他状态(托管对象)。
End If
conn = Nothing
dbTrans = Nothing
' TODO: 释放您自己的状态(非托管对象)。
' TODO: 将大型字段设置为 null。
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' Visual Basic 添加此代码是为了正确实现可处置模式。
Public Sub Dispose() Implements IDisposable.Dispose
' 不要更改此代码。请将清理代码放入上面的 Dispose(ByVal disposing As Boolean) 中。
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
您可能感兴趣的文章: