db

原创
2018/08/08 07:17
阅读数 36

Option Explicit

Public m_Conn As New ADODB.Connection

Public m_Rec As New ADODB.Recordset

Public m_Comm As New ADODB.Command

' 用户?

Private Const DB_UserId = "vbatest"

'Private Const DB_UserId = "TEST1"

' ?

Private Const DB_Password = "a"

'Private Const DB_Password = "TEST1"

' 数据?

Private Const DB_Catalog = "my11"

'Private Const DB_Catalog = "ORDB"

'************************************************************************************************

'* 功能 DB连接

'* 参数

'* 返回值:

'* 备注

'************************************************************************************************

Public Function DB_Connect() As Boolean

On Error GoTo Error_DB

Call DB_Close

m_Conn.Open "Provider=MSDAORA;" & _

"Data Source=" + DB_Catalog + ";", DB_UserId, DB_Password

m_Conn.CursorLocation = adUseClient

m_Comm.ActiveConnection = m_Conn

DB_Connect = True

Exit Function

Error_DB:

DB_Connect = False

Set m_Conn = Nothing

Call WriteLog(Log_Error, "DB_CONNECT", Err.Description)

End Function

'************************************************************************************************

'* 功能 画面数据关闭

'* 参数

'* 返回值:

'* 备注

'************************************************************************************************

Public Sub DB_Close()

If m_Rec.State = 1 Then

m_Rec.Close

End If

If m_Conn.State = 1 Then

m_Conn.Close

End If

End Sub

'************************************************************************************************

'* 功能 开始一个事务

'* 参数

'* 返回值:

'* 备注

'************************************************************************************************

Public Sub DB_Start()

If m_Conn.State = 1 Then

m_Conn.BeginTrans

'm_Conn.Close

End If

End Sub

'************************************************************************************************

'* 功能 回滚

'* 参数

'* 返回值:

'* 备注

'************************************************************************************************

Public Sub DB_Rollback()

If m_Rec.State = 1 Then

m_Rec.Close

End If

If m_Conn.State = 1 Then

m_Conn.RollbackTrans

'm_Conn.Close

End If

End Sub

'************************************************************************************************

'* 功能 Commit

'* 参数

'* 返回值:

'* 备注

'************************************************************************************************

Public Sub DB_Commit()

If m_Rec.State = 1 Then

m_Rec.Close

End If

If m_Conn.State = 1 Then

m_Conn.CommitTrans

'm_Conn.Close

End If

End Sub

展开阅读全文
打赏
0
0 收藏
分享

作者的其它热门文章

加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部