📄 frmdatabaseconninfo.frm
字号:
VERSION 5.00
Begin VB.Form frmDatabaseConnInfo
BorderStyle = 1 'Fixed Single
Caption = "数据库连接参数设定"
ClientHeight = 2895
ClientLeft = 45
ClientTop = 330
ClientWidth = 4125
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2895
ScaleWidth = 4125
StartUpPosition = 1 '所有者中心
Begin VB.TextBox txtDatabase
Height = 270
Left = 1080
TabIndex = 10
Text = "txtDatabase"
Top = 1560
Width = 2535
End
Begin VB.TextBox txtPassWord
Height = 270
IMEMode = 3 'DISABLE
Left = 1080
PasswordChar = "*"
TabIndex = 9
Text = "txtPassWord"
Top = 1120
Width = 2535
End
Begin VB.TextBox txtUser
Height = 270
Left = 1080
TabIndex = 8
Text = "txtUser"
Top = 680
Width = 2535
End
Begin VB.TextBox txtServer
Height = 270
Left = 1080
TabIndex = 7
Text = "txtServer"
Top = 240
Width = 2535
End
Begin VB.CommandButton cmdCancle
Caption = "放弃"
Height = 375
Left = 2835
TabIndex = 6
Top = 2280
Width = 975
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Height = 375
Left = 1575
TabIndex = 5
Top = 2280
Width = 975
End
Begin VB.CommandButton cmdTest
Caption = "测试"
Height = 375
Left = 315
TabIndex = 4
Top = 2280
Width = 975
End
Begin VB.Label lblErrorInfo
Caption = "lblErrorInfo"
ForeColor = &H000000FF&
Height = 255
Left = 360
TabIndex = 11
Top = 1920
Width = 3495
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "数据库"
Height = 180
Left = 360
TabIndex = 3
Top = 1605
Width = 540
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "密 码"
Height = 180
Left = 360
TabIndex = 2
Top = 1165
Width = 540
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "用户名"
Height = 180
Left = 360
TabIndex = 1
Top = 725
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "服务器"
Height = 180
Left = 360
TabIndex = 0
Top = 285
Width = 540
End
End
Attribute VB_Name = "frmDatabaseConnInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'***********************************************************************
'* 过程名:cmdCancle_Click
'* 功 能:放弃按钮CLICK事件响应
'* 参 数:
'* 版 本:2006.01.06 颜志军 初版
'***********************************************************************
Private Sub cmdCancle_Click()
Unload Me
End Sub
'***********************************************************************
'* 过程名:cmdOK_Click
'* 功 能:确定按钮CLICK事件响应
'* 参 数:
'* 版 本:2006.01.06 颜志军 初版
'***********************************************************************
Private Sub cmdOK_Click()
If CheckInput() Then
'变量定义
Dim cfgFile As clsConfigFile
Dim server As String
Dim user As String
Dim pwd As String
Dim dataName As String
'取得设定值
server = Trim(txtServer.Text)
user = Trim(txtUser.Text)
pwd = Trim(txtPassWord.Text)
dataName = Trim(txtDatabase.Text)
'写入配置
Set cfgFile = New clsConfigFile
cfgFile.WriteDatabasePara server, user, pwd, dataName
'关闭窗口
Unload Me
End If
End Sub
'***********************************************************************
'* 过程名:cmdTest_Click
'* 功 能:测试按钮CLICK事件响应
'* 参 数:
'* 版 本:2006.01.06 颜志军 初版
'***********************************************************************
Private Sub cmdTest_Click()
If CheckInput() Then
'变量定义
Dim conn As ADODB.Connection
Dim server As String
Dim user As String
Dim pwd As String
Dim dataName As String
'取得设定值
server = Trim(txtServer.Text)
user = Trim(txtUser.Text)
pwd = Trim(txtPassWord.Text)
dataName = Trim(txtDatabase.Text)
'测试连接
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB;Data Source=" & server & _
";Initial Catalog=" & dataName & _
";User Id=" & user & _
";Password=" & pwd & ";"
On Error GoTo SUBEND
conn.Open
If conn.State = adStateOpen Then
MsgBox "数据库测试连接成功!", vbInformation Or vbOKOnly, "信息"
Exit Sub
End If
End If
SUBEND:
MsgBox "数据库测试连接失败!", vbExclamation Or vbOKOnly, "信息"
End Sub
'***********************************************************************
'* 过程名:Form_Load
'* 功 能:窗体LOAD事件响应
'* 参 数:
'* 版 本:2006.01.06 颜志军 初版
'***********************************************************************
Private Sub Form_Load()
'变量定义
Dim cfgFile As clsConfigFile '配置读写对象
Dim server As String '服务器
Dim userName As String '用户名
Dim passWord As String '密码
Dim database As String '数据库
'取得设定值
Set cfgFile = New clsConfigFile
cfgFile.GetDatabasePara server, userName, passWord, database
'显示设定值
txtServer.Text = server
txtUser.Text = userName
txtPassWord.Text = passWord
txtDatabase.Text = database
'清空错误信息
lblErrorInfo.Caption = ""
End Sub
'***********************************************************************
'* 过程名:CheckInput
'* 功 能:检查输入信息
'* 参 数:
'* 版 本:2006.01.06 颜志军 初版
'***********************************************************************
Private Function CheckInput() As Boolean
If Trim(txtServer.Text) = "" Then
lblErrorInfo.Caption = "请输入服务器名或IP!"
CheckInput = False
ElseIf Trim(txtUser.Text) = "" Then
lblErrorInfo.Caption = "请输入用户名!"
CheckInput = False
ElseIf Trim(txtPassWord.Text) = "" Then
lblErrorInfo.Caption = "请输入密码!"
CheckInput = False
ElseIf Trim(txtDatabase.Text) = "" Then
lblErrorInfo.Caption = "请输入数据库名称!"
CheckInput = False
Else
CheckInput = True
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -