📄 frmconnect.frm
字号:
VERSION 5.00
Begin VB.Form frmConnect
BorderStyle = 1 'Fixed Single
Caption = "连接数据库"
ClientHeight = 6210
ClientLeft = 45
ClientTop = 330
ClientWidth = 6090
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 6210
ScaleWidth = 6090
Begin VB.Frame FrameConnect
Height = 4455
Left = 240
TabIndex = 8
Top = 480
Width = 5535
Begin VB.ComboBox cmbServer
Height = 315
Left = 2040
TabIndex = 0
Text = "(local)"
Top = 720
Width = 2775
End
Begin VB.OptionButton OptionWindows
Caption = "使用 windows 身份验证"
Height = 375
Left = 360
TabIndex = 1
Top = 1320
Width = 4455
End
Begin VB.OptionButton OptionSqlServer
Caption = "使用SQL Server 身份验证"
Height = 495
Left = 360
TabIndex = 2
Top = 1800
Value = -1 'True
Width = 4695
End
Begin VB.TextBox txtUser
Height = 315
Left = 2040
TabIndex = 3
Text = "sa"
Top = 2400
Width = 2775
End
Begin VB.TextBox txtPassword
Height = 315
IMEMode = 3 'DISABLE
Left = 2040
PasswordChar = "*"
TabIndex = 4
Text = "sa"
Top = 2880
Width = 2775
End
Begin VB.ComboBox cmbDatabase
Height = 315
Left = 2040
TabIndex = 5
Text = "sellsystem"
Top = 3480
Width = 2775
End
Begin VB.Label Label1
Caption = "连接到SQL Server,必须指定服务器、用户名和密码。"
Height = 375
Left = 480
TabIndex = 13
Top = 240
Width = 4335
End
Begin VB.Label Label2
Caption = "服务器:"
Height = 375
Left = 360
TabIndex = 12
Top = 720
Width = 1455
End
Begin VB.Label lblUser
Caption = "用户名:"
Height = 255
Left = 480
TabIndex = 11
Top = 2400
Width = 1095
End
Begin VB.Label lblPassword
Caption = "密码:"
Height = 375
Left = 480
TabIndex = 10
Top = 2880
Width = 1095
End
Begin VB.Label Label5
Caption = "数据库:"
Height = 375
Left = 360
TabIndex = 9
Top = 3480
Width = 1095
End
End
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 495
Left = 3600
TabIndex = 7
Top = 5280
Width = 1695
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 495
Left = 600
TabIndex = 6
Top = 5280
Width = 1695
End
End
Attribute VB_Name = "frmConnect"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdConnect_Click()
If OptionWindows.Value = True Then 'windows身份验证方式
connStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" _
+ "Persist Security Info=False;Initial Catalog=" + Trim(cmbDatabase.Text) _
+ ";Data Source=" + Trim(cmbServer.Text)
Else 'SQL Server身份验证方式
connStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" _
+ Trim(txtUser.Text) + ";Password=" + Trim(txtPassword.Text) _
+ ";Initial Catalog=" + Trim(cmbDatabase.Text) + ";Data Source=" _
+ Trim(cmbServer.Text)
End If
On Error GoTo errConnect
If conn.State = adStateOpen Then
conn.Close
End If
conn.Open connStr
MsgBox "连接数据库成功!", vbOKOnly + vbExclamation, "提示"
'显示登录窗体
frmLogin.Show
frmLogin.SetFocus
Unload Me
Exit Sub
errConnect:
MsgBox Err.Description, vbOKOnly + vbExclamation, "提示"
End Sub
Private Sub Form_Load()
'让窗体居中
Call MakeCenter(Me)
End Sub
Private Sub OptionSqlServer_Click()
If OptionSqlServer.Value = True Then
lblUser.Enabled = True
lblPassword.Enabled = True
txtUser.Enabled = True
txtPassword.Enabled = True
End If
End Sub
Private Sub OptionWindows_Click()
If OptionWindows.Value = True Then
lblUser.Enabled = False
lblPassword.Enabled = False
txtUser.Enabled = False
txtPassword.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -