?? clsdbstate.cls
字號:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsDbState"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
'***********************************************************************
'* 函數名:GetConnState
'* 功 能:取得數據庫連接狀態
'* 參 數:
'* 版 本:2005.12.29 顏志軍 初版
'***********************************************************************
Public Function GetConnState() As Boolean
If g_conn Is Nothing Or Not IsObject(g_conn) Then
GetConnState = False
Exit Function
End If
If g_conn.State = adStateOpen Then
GetConnState = True
Else
GetConnState = False
End If
End Function
'***********************************************************************
'* 函數名:ConnDb
'* 功 能:連接數據庫
'* 參 數:
'* 版 本:2005.12.29 顏志軍 初版
'***********************************************************************
Private Function ConnDb() As Boolean
If GetConnState() Then
Exit Function
End If
On Error Resume Next
'取得數據庫參數設定信息
Dim cfgFile As clsConfigFile '配置文件類
Dim server As String '服務器
Dim user As String '用戶名
Dim pwd As String '密碼
Dim dataName As String '數據庫名
Set cfgFile = New clsConfigFile
cfgFile.GetDatabasePara server, user, pwd, dataName
server = Trim(server)
user = Trim(user)
pwd = Trim(pwd)
dataName = Trim(dataName)
'判斷各參數是否為空
If IsNull(server) Or IsEmpty(server) Or server = "" _
Or IsNull(user) Or IsEmpty(user) Or user = "" _
Or IsNull(pwd) Or IsEmpty(pwd) Or pwd = "" _
Or IsNull(dataName) Or IsEmpty(dataName) Or dataName = "" Then
ConnDb = False
Exit Function
End If
'連接數據庫
ConnDb = False
On Error GoTo FUNEND
Set g_conn = New ADODB.Connection
g_conn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & server & _
";Initial Catalog=" & dataName & _
";User Id=" & user & _
";Password=" & pwd & ";"
g_conn.Open
If g_conn.State = adStateOpen Then
ConnDb = True
Else
ConnDb = False
End If
FUNEND:
End Function
Private Sub Class_Initialize()
ConnDb
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -