【VB开源代码栏目提醒】:网学会员VB开源代码为您提供frmBackRest.frm参考,解决您在frmBackRest.frm学习中工作中的难题,参考学习。
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmdataback
Caption = "备份/还原数据库"
ClientHeight = 2955
ClientLeft = 60
ClientTop = 345
ClientWidth = 5940
Icon = "frmBackRest.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 2955
ScaleWidth = 5940
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "退出"
Height = 495
Left = 4380
TabIndex = 7
Top = 2100
Width = 1245
End
Begin VB.CommandButton cmdBackup
Caption = "备份"
Height = 465
Left = 4350
TabIndex = 4
Top = 840
Width = 1215
End
Begin VB.CommandButton cmdRestore
Caption = "还原"
Height = 495
Left = 4380
TabIndex = 3
Top = 1470
Width = 1215
End
Begin VB.ComboBox cmbDatabaseName
Height = 300
Left = 390
TabIndex = 1
Top = 810
Width = 3375
End
Begin VB.CommandButton cmdBrowse
Caption = "..."
Height = 285
Left = 3360
TabIndex = 0
Top = 2220
Width = 405
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 3270
Top = 1170
_ExtentX = 847
_ExtentY = 847
_Version = 393216
DialogTitle = "Data File Name:"
End
Begin VB.TextBox txtDataFileName
Height = 345
Left = 420
TabIndex = 2
Top = 2190
Width = 3375
End
Begin
VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "数据库备份/还原到:"
Height = 180
Left = 390
TabIndex = 6
Top = 450
Width = 1620
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "备份/还原的文件名称:"
Height = 255
Left = 390
TabIndex = 5
Top = 1890
Width = 2145
End
End
Attribute VB_Name = "frmdataback"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim gSQLServer As SQLDMO.SQLServer
Dim WithEvents oBackupEvent As SQLDMO.Backup
Attribute oBackupEvent.VB_VarHelpID = -1
Dim WithEvents oRestoreEvent As SQLDMO.Restore
Attribute oRestoreEvent.VB_VarHelpID = -1
Dim gbConnected As Boolean
Dim gDatabaseName As String
Dim gBkupRstrFileName As String
Dim gBkupRstrFilePath As String
Const gTitle = "服务器连接"
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set gSQLServer = Nothing
gbConnected = False
buttonsConnectClosed
Dim ServerName As String
Dim UserName As String
Dim Password As String
On Error GoTo ErrHandler:
If gSQLServer Is Nothing Then
Set gSQLServer = New SQLDMO.SQLServer
End If
ServerName = "JIMMY"
UserName = "sa"
Password = ""
gSQLServer.Connect ServerName, UserName, Pass
word gbConnected = True
FillDatabaseList
buttonsConnectOpen
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Description
If Screen.MousePointer = vbHourglass Then
Screen.MousePointer = vbDefault
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If gbConnected = True Then
Call gSQLServer.DisConnect
End If
If Not gSQLServer Is Nothing Then
Set gSQLServer = Nothing
End If
End Sub
Private Sub cmdBackup_Click()
On Error GoTo ErrHandler:
Dim oBackup As SQLDMO.Backup
gDatabaseName = cmbDatabaseName.Text
Set oBackup = New SQLDMO.Backup
Set oBackupEvent = oBackup ' enable events
oBackup.Database = gDatabaseName
gBkupRstrFileName = txtDataFileName.Text
oBackup.Files = gBkupRstrFileName
If Len(Dir(gBkupRstrFileName)) > 0 Then
Kill (gBkupRstrFileName)
End If
oBackup.SQLBackup gSQLServer
Set oBackupEvent = Nothing ' disable events
Set oBackup = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Description
Resume Next
End Sub
Private Sub cmdRestore_Click()
On Error GoTo ErrHandler:
Dim oRestore As SQLDMO.Restore
Dim Msg As String
Dim Response As String
gDatabaseName = cmbDatabaseName.Text
Set oRestore = New SQLDMO.Restore
Set oRestoreEvent = oRestore ' enable events
oRestore.Database = gDatabaseName
gBkupRstrFileName = txtDataFileName.Text
oRestore.Files = gBkupRstrFileName
Screen.MousePointer = vbHourglass
oRestore.SQLRestore gSQLServer
Screen.MousePointer = vbDefault
Set oRestoreEvent = Nothing ' disable events
Set oRestore = Nothing
Exit Sub
ErrHandler:
MsgBox "Error " & Err.Description
Resume Next
End Sub
Private Sub cmdBrowse_Click()
On Error GoTo ErrHandler:
CommonDialog1.CancelError = True
CommonDialog1.Filter = "All Files (*.*)|*.*|Backup Files (*.bak)|*.bak"
CommonDialog1.FilterIndex = 2
CommonDialog1.InitDir = gBkupRstrFilePath
CommonDialog1.DefaultExt = "bak"
CommonDialog1.DialogTitle = "Data File Name:"
CommonDialog1.Action = 1
txtDataFileName.Text = CommonDialog1.FileName
Exit Sub
ErrHandler:
Exit Sub
End Sub
Private Sub oBackupEvent_C