VB. net dmo SQL SERVER Backup Recovery

Source: Internet
Author: User

VB. net dmo SQL Server Backup RecoveryPublic class form1 inherits system. Windows. Forms. Form # region "code generated by the Windows Form Designer" Public sub new ()
Mybase. New () 'is required by the Windows Form Designer.
Initializecomponent () 'After initializecomponent () is called, add any initialization end sub' form rewriting disposal to clear the component list.
Protected overloads overrides sub dispose (byval disposing as Boolean)
If disposing then
If not (components is nothing) then
Components. Dispose ()
End If
End If
MyBase. Dispose (disposing)
End Sub required by the Windows Form Designer
Private components As System. ComponentModel. IContainer Note: The following process is required by the Windows Forms designer
'You can use the Windows Form Designer to modify this process.
'Do not use the code editor to modify it.
Friend WithEvents ProgressBar1 As System. Windows. Forms. ProgressBar
Friend WithEvents Button1 As System. Windows. Forms. Button
<System. Diagnostics. DebuggerStepThrough ()> Private Sub InitializeComponent ()
Me. ProgressBar1 = New System. Windows. Forms. ProgressBar ()
Me. Button1 = New System. Windows. Forms. Button ()
Me. SuspendLayout ()
'
'Ssssbar1
'
Me. ProgressBar1.Anchor = (System. Windows. Forms. AnchorStyles. Top Or System. Windows. Forms. AnchorStyles. Left )_
Or System. Windows. Forms. AnchorStyles. Right)
Me. ProgressBar1.Location = New System. Drawing. Point (8, 8)
Me. ProgressBar1.Name = "ProgressBar1"
Me. ProgressBar1.Size = New System. Drawing. Size (384, 23)
Me. ProgressBar1.TabIndex = 0
'
'Button1
'
Me. Button1.FlatStyle = System. Windows. Forms. FlatStyle. Flat
Me. Button1.Location = New System. Drawing. Point (160, 40)
Me. Button1.Name = "Button1"
Me. Button1.Size = New System. Drawing. Size (75, 24)
Me. Button1.TabIndex = 1
Me. Button1.Text = "backup"
'
'Form1
'
Me. AutoScaleBaseSize = New System. Drawing. Size (6, 14)
Me. BackColor = System. Drawing. Color. CornflowerBlue
Me. ClientSize = New System. Drawing. Size (400, 74)
Me. Controls. AddRange (New System. Windows. Forms. Control () {Me. Button1, Me. ProgressBar1 })
Me. FormBorderStyle = System. Windows. Forms. FormBorderStyle. FixedToolWindow
Me. MaximizeBox = False
Me. MinimizeBox = False
Me. Name = "Form1"
Me. ShowInTaskbar = False
Me. StartPosition = System. Windows. Forms. FormStartPosition. CenterScreen
Me. ResumeLayout (False) End Sub # End Region 'Here, due to too much trouble, it is not processed by attributes ...... Improvements should be made
Public sa As String
Public passerd As String
Public file As String
Public database As String
Public sqlserver As String Public flag As Boolean = True
Private WithEvents PBackup As New SQLDMO. Backup ()
Private WithEvents oRestore As New SQLDMO. Restore () 'Property SQLServerName () As String
'Get
'Return sqlserver
'End Get
'Set (ByVal Value As String)
'Sqlserver = Value
'End Set
'End Property
'Backup
Public Function BACKUP (ByVal DATABASENAME As String, ByVal SQLServe As String, ByVal ROLE As String, ByVal PASSWORD As String, ByVal backfilename As String)
Me. ProgressBar1.Value = 0
Me. BackColor = System. Drawing. Color. RoyalBlue
Me. Button1.Text = "backup"
Me. Show ()
On Error GoTo ErrHandler Dim SQLSER As New SQLDMO. SQLServer SQLSER. Connect (SQLServe, ROLE, PASSWORD)
PBackup. Database = DATABASENAME System. Windows. Forms. Cursor. Current = System. Windows. Forms. Cursors. WaitCursor PBackup. Files = backfilename
PBackup. SQLBackup (SQLSER) SQLSER. DisConnect ()
SQLSER = Nothing
System. Windows. Forms. Cursor. Current = System. Windows. Forms. Cursors. Default
Exit FunctionErrHandler: MsgBox ("backup failed. Check whether the source database exists, whether the role permission is sufficient, or whether the SQL SERVER service is enabled" & Chr (13) & "information: "& Err. description)
Resume Next
End Function 'Restore
Public Function RSTORE (ByVal DATABASENAME As String, ByVal SQLServe As String, ByVal ROLE As String, ByVal PASSWORD As String, ByVal restfilename As String) Me. progressBar1.Value = 0 Me. backColor = System. drawing. color. oliveDrab
Me. Button1.Text = "Restore"
Me. Show ()
On Error GoTo ErrHandler
Dim SQLSER As New SQLDMO. SQLServer SQLSER. Connect (SQLServe, ROLE, PASSWORD) oRestore. Database = DATABASENAME
ORestore. Files = restfilename
System. Windows. Forms. Cursor. Current = System. Windows. Forms. Cursors. WaitCursor
ORestore. SQLRestore (SQLSER)
System. Windows. Forms. Cursor. Current = System. Windows. Forms. Cursors. Default SQLSER. DisConnect ()
SQLSER = Nothing Exit FunctionErrHandler:
MsgBox ("recovery failed. Please check whether the restoration database exists, whether the role permissions are sufficient, or whether the SQL SERVER service is enabled" & Chr (13) & "information:" & Err. Description)
Resume Next
End Function
Private Sub PBackup_Complete (ByVal Message As String) Handles PBackup. Complete Me. ProgressBar1.Value = 100
PBackup = Nothing
Me. oRestore = Nothing
Me. Close () End Sub
Private Sub PBackup_PercentComplete (ByVal Message As String, ByVal Percent As Integer) Handles PBackup. PercentComplete
Me. BackColor = System. Drawing. Color. RoyalBlue Me. ProgressBar1.Value = Percent
If Percent = 100 Then Me. ProgressBar1.Value = 100
PBackup = Nothing
Me. oRestore = Nothing
Me. Close () End If
End Sub
Private Sub oRestore_Complete (ByVal Message As String) Handles oRestore. Complete Me. ProgressBar1.Value = 100
PBackup = Nothing
Me. oRestore = Nothing
Me. Close ()
End Sub
Private Sub oRestore_PercentComplete (ByVal Message As String, ByVal Percent As Integer) Handles oRestore. PercentComplete
Me. BackColor = System. Drawing. Color. OliveDrab Me. ProgressBar1.Value = Percent
If Percent = 100 Then Me. ProgressBar1.Value = 100
PBackup = Nothing
Me. oRestore = Nothing
Me. Close ()
End if
End sub private sub button#click (byval sender as system. Object, byval e as system. eventargs) handles button1.click
If flag = true then me. Backup (Me. Database, me. sqlserver, me. SA, me. passerd, me. File) else
Me. rstore (Me. Database, me. sqlserver, me. SA, me. passerd, me. File) end if end sub
End Class

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.