📄 backup.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmBackup
BorderStyle = 1 'Fixed Single
Caption = "SQL Server数据库备份窗体设计"
ClientHeight = 4965
ClientLeft = 45
ClientTop = 330
ClientWidth = 8655
Icon = "Backup.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4965
ScaleWidth = 8655
StartUpPosition = 1 '所有者中心
Begin VB.Frame Frame3
Caption = "请选择数据库"
Height = 615
Left = 4560
TabIndex = 12
Top = 480
Width = 4095
Begin VB.ComboBox Combo1
Height = 300
Left = 120
TabIndex = 13
Top = 240
Width = 3735
End
End
Begin MSComDlg.CommonDialog filSelect
Left = 840
Top = 4440
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Frame Frame2
Caption = "请选择数据库路径"
Height = 2820
Left = 4545
TabIndex = 6
Top = 1200
Width = 4065
Begin VB.DriveListBox Drive1
Height = 300
Left = 150
TabIndex = 9
Top = 240
Width = 3750
End
Begin VB.DirListBox Dir1
Height = 720
Left = 120
TabIndex = 8
Top = 600
Width = 3750
End
Begin VB.FileListBox File1
Height = 1350
Left = 120
Pattern = "*.BAK"
TabIndex = 7
Top = 1320
Width = 3750
End
End
Begin VB.Frame Frame1
Caption = "备份卡列表"
Height = 3540
Left = 120
TabIndex = 4
Top = 360
Width = 4350
Begin MSComctlLib.ListView ListView1
Height = 3180
Left = 120
TabIndex = 5
Top = 240
Width = 4050
_ExtentX = 7144
_ExtentY = 5609
Sorted = -1 'True
LabelWrap = 0 'False
HideSelection = -1 'True
HoverSelection = -1 'True
_Version = 393217
Icons = "ImageList1"
SmallIcons = "ImageList1"
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 1
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Object.Width = 2540
EndProperty
End
End
Begin VB.OptionButton Option2
Caption = "数据还原"
Height = 300
Left = 6360
TabIndex = 3
Top = 90
Width = 1740
End
Begin VB.OptionButton Option1
Caption = "数据备份"
Height = 300
Left = 4605
TabIndex = 2
Top = 90
Width = 1740
End
Begin VB.CommandButton CmdEnd
Caption = "退出"
Height = 420
Left = 4350
TabIndex = 1
Top = 4455
Width = 1830
End
Begin VB.CommandButton CmdBackup
Caption = "数据备份或数据恢复"
Height = 420
Left = 2520
TabIndex = 0
Top = 4455
Width = 1830
End
Begin MSComctlLib.ImageList ImageList1
Left = -135
Top = 1560
_ExtentX = 1005
_ExtentY = 1005
BackColor = -2147483643
ImageWidth = 32
ImageHeight = 32
MaskColor = 12632256
_Version = 393216
BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
NumListImages = 2
BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Backup.frx":000C
Key = ""
EndProperty
BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
Picture = "Backup.frx":08E8
Key = ""
EndProperty
EndProperty
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "请选择数据备份或数据恢复选项"
ForeColor = &H000000FF&
Height = 300
Left = 75
TabIndex = 11
Top = 120
Width = 2580
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
ForeColor = &H000000FF&
Height = 375
Left = 60
TabIndex = 10
Top = 4050
Width = 8025
End
End
Attribute VB_Name = "frmBackup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim StrCnn As New ADODB.Connection '定义连接
Dim itmX As ListItem '定义一个ListItem对象
Dim key, list, sql As String '定义字符串变量
Private Sub Form_Load()
Me.Caption = "数据库备份"
Option1.Value = True '设置Option1的值为真
Dir1_Change
Dim n As Integer
For n = 0 To frmDatabase.Combo1.ListCount - 1
Combo1.AddItem frmDatabase.Combo1.list(n)
Next n
Combo1.ListIndex = frmDatabase.Combo1.ListIndex
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
'添加数据备份卡到列表中
ListView1.ListItems.Clear
If File1.ListCount <> 0 Then
a = 0 '给变量a设置初值
Do While File1.ListIndex < File1.ListCount - 1
File1.ListIndex = a '赋值给变量a
key = File1.FileName
Set itmX = ListView1.ListItems.Add(, , key, 1)
a = a + 1
Loop
End If
File1_Click
End Sub
Private Sub Drive1_Change()
On Error GoTo Dv_Err
Dir1.Path = Drive1.Drive
Exit Sub
Dv_Err:
MsgBox "设备不可用"
End Sub
Private Sub File1_Click()
Label1.Caption = Dir1.Path & "\" & File1.FileName '获得路径
End Sub
Private Sub ListView1_Click()
Label1.Caption = Dir1.Path & "\" & ListView1.SelectedItem '获得路径
End Sub
Private Sub CmdBackup_Click()
Dim S
Dim Constr As String
Constr = ChangeDB(gdbConString) & Combo1.Text
If Option1.Value = True Then
'备份数据库
On Error GoTo nofile
filSelect.Filter = "备份文件|*.BAK"
filSelect.CancelError = True
filSelect.ShowSave
S = filSelect.FileName
If Label1.Caption = S Then
MsgBox "数据备份卡已存在!"
Else
StrCnn.Open Constr
'数据备份语句
sql = "backup DATABASE " & Combo1.Text & " TO disk='" & S & "'"
StrCnn.Execute (sql) '执行SQL语句
On Error GoTo bk_err
StrCnn.Close
MsgBox "数据库备份成功!"
key = filSelect.FileTitle
Set itmX = ListView1.ListItems.Add(, , key, 1)
File1.Refresh
End If
End If
If Option2.Value = True Then
'恢复指定路径下的数据库
If File1.ListCount <> 0 Then
If Label1.Caption <> "" Then
StrCnn.Open Constr
On Error GoTo bk_err
'数据恢复语句
sql = "RESTORE DATABASE " & Combo1.Text & " from disk='" & Label1.Caption & "'"
StrCnn.Execute (sql) '执行SQL语句
StrCnn.Close
MsgBox "数据库恢复成功!"
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
Else
MsgBox "请选择要恢复的数据备份卡!"
End If
End If
Exit Sub
nofile:
If Err.Number = 32755 Then
Else
Exit Sub
End If
bk_err:
Dim errloop As ADODB.Error
Dim strerror As String
For Each errloop In StrCnn.Errors
strerror = errloop.Description & vbCr
MsgBox strerror
Next
StrCnn.Close
End Sub
Private Sub CmdEnd_Click()
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -