📄 frmbackupandrestore.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmBackupAndRestore
BorderStyle = 3 'Fixed Dialog
Caption = "数据备份与恢复"
ClientHeight = 4710
ClientLeft = 45
ClientTop = 330
ClientWidth = 6345
Icon = "frmBackupAndRestore.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4710
ScaleWidth = 6345
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.TextBox txtDatabase
Height = 300
Left = 1695
TabIndex = 10
Top = 810
Width = 4095
End
Begin VB.TextBox Text2
BackColor = &H80000018&
Height = 1980
Left = 180
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 8
Text = "frmBackupAndRestore.frx":0442
Top = 1830
Width = 5940
End
Begin VB.CommandButton cmdExit
Caption = "退出[&X]"
Height = 555
Left = 4080
TabIndex = 5
Top = 3990
Width = 1455
End
Begin VB.CommandButton cmdRestore
Caption = "恢复[&R]"
Height = 555
Left = 2385
TabIndex = 4
Top = 3990
Width = 1455
End
Begin VB.CommandButton cmdBackup
Caption = "备份[&B]"
Height = 555
Left = 705
TabIndex = 3
Top = 3990
Width = 1455
End
Begin MSComDlg.CommonDialog dlgFile
Left = 4950
Top = -30
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton cmdSelectFile
Caption = "..."
Height = 330
Left = 5805
TabIndex = 2
Top = 330
Width = 405
End
Begin VB.TextBox txtFileName
Height = 300
Left = 1695
TabIndex = 1
Top = 360
Width = 4095
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "数据库名称:"
Height = 180
Left = 585
TabIndex = 9
Top = 855
Width = 1080
End
Begin VB.Label lblMsg
BorderStyle = 1 'Fixed Single
Height = 315
Left = 1680
TabIndex = 7
Top = 1245
Width = 4125
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "状态信息:"
Height = 180
Left = 720
TabIndex = 6
Top = 1305
Width = 900
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "数据备份文件名:"
Height = 180
Left = 225
TabIndex = 0
Top = 420
Width = 1440
End
End
Attribute VB_Name = "frmBackupAndRestore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdBackup_Click()
On Error GoTo BackupErr
' Conn.BeginTrans
Cmd.ActiveConnection = Conn
'-- Create the backup device for the full database backup.
sSQL = "USE master"
Cmd.CommandText = sSQL
Cmd.Execute
' lblMsg.Caption = "正在建立备份设备..."
' sSQL = "EXEC sp_addumpdevice 'disk', 'FreeSoft','" & Trim(txtFileName.Text) & "'"
' Cmd.CommandText = sSQL
' Cmd.Execute
'-- Back up the full database.
lblMsg.Caption = "正在备份数据..."
sSQL = "BACKUP DATABASE " & Trim(txtDatabase.Text) & " TO DISK='" & Trim(txtFileName.Text) & "'"
Cmd.CommandText = sSQL
Cmd.Execute
' '--drop the backup device
'
' lblMsg.Caption = "正在删除备份设备..."
' sSQL = "EXEC sp_dropdevice 'FreeSoft'"
' Cmd.CommandText = sSQL
' Cmd.Execute
' Conn.CommitTrans
MsgBox "成功备份数据库!!!", vbInformation, "提示窗口"
lblMsg.Caption = "成功备份数据!"
sSQL = "USE " & Trim(txtDatabase.Text)
Cmd.CommandText = sSQL
Cmd.Execute
Exit Sub
BackupErr:
' Conn.RollbackTrans
sSQL = "USE " & Trim(txtDatabase.Text)
Cmd.CommandText = sSQL
Cmd.Execute
MsgBox "备份数据库时发生错误!!!", vbInformation, "提示窗口"
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdRestore_Click()
On Error GoTo RestoreErr
Dim xMac, xDataBase, xUid, xPwd
xMac = GetSetting("LSDSTAR", "数据库信息", "机器名", "NT_SERVER")
xDataBase = GetSetting("LSDSTAR", "数据库信息", "数据库名", "DSTAR")
xUid = GetSetting("LSDSTAR", "数据库信息", "用户名", "SCC")
xPwd = GetSetting("LSDSTAR", "数据库信息", "口令", "SCC")
If MsgBox("强烈建议在恢复数据时请先备份数据!!!" & vbCrLf & "恢复数据库将覆盖掉现有数据!!!,继续吗?", vbQuestion + vbYesNo, "提示窗口") = vbNo Then Exit Sub
lblMsg.Caption = "正在恢复备份..."
Cmd.ActiveConnection = Conn
sSQL = "USE master"
Cmd.CommandText = sSQL
Cmd.Execute
Set Conn = Nothing
Conn.Open "driver={SQL Server};" & _
"server=" & xMac & ";uid=" & xUid & ";pwd=" & xPwd & ";database=master;"
sSQL = "RESTORE DATABASE " & Trim(txtDatabase.Text) & " FROM DISK = '" & Trim(txtFileName.Text) & "'"
Cmd.CommandText = sSQL
Cmd.Execute
MsgBox "成功恢复数据库!!!", vbInformation, "提示窗口"
lblMsg.Caption = "成功恢复数据库!"
Set Conn = Nothing
Conn.Open ConnectString
sSQL = "USE " & Trim(txtDatabase.Text)
Cmd.CommandText = sSQL
Cmd.Execute
Exit Sub
RestoreErr:
sSQL = "USE " & Trim(txtDatabase.Text)
Cmd.CommandText = sSQL
Cmd.Execute
MsgBox "恢复数据库时发生错误!!!", vbInformation, "提示窗口"
End Sub
Private Sub cmdSelectFile_Click()
On Error Resume Next
dlgFile.FileName = "Backup" & Format(Now, "yymmdd") & ".bak"
dlgFile.ShowOpen
txtFileName.Text = dlgFile.FileName
End Sub
Private Sub Form_Load()
txtFileName.Text = App.Path & "\Backup" & Format(Now, "yymmdd") & ".bak"
txtDatabase.Text = GetSetting("LSDSTAR", "数据库信息", "数据库名", "DSTAR")
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -