VB.NET DMO SQL Server Backup Recovery

xiaoxiao2021-03-06  69

Public class form1 inherits system.windows.Forms.Form #Region "Windows Form Designer Generated Code" Public Sub New () MyBase.new () 'This call is required for the Windows Form Designer. InitializationComponent () 'Add any initialization End Sub' form rewriting to clean the component list after the initializationComponent () call. 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 'Windows Form Designer Private components required As system.componentmodel.icontainer 'Note: The following procedure is required to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar Friend WithEvents Button1 As System.Windows.Forms.Button Private Sub InitializeComponent () Me.ProgressBar1 = New System.Windows.Forms.ProgressBar () Me.Button1 = New System.Windows.Forms.Button () Me.SuspendLayout () '' ProgressBar1 '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.formolderstyle.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 'This is not processed by the attribute because it is troubles that 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 S QLSER 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 function errhandler: msgbox ("Backup failed, please check if the source database exists, the role permission is enough or Whether the SQL Server service is opened "& Chr (13) &" information: "& Err.Description) Resume next end function '

Recovery 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 = "recovery" 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 Function ErrHandler: MsgBox ("Recovery failed, please check if the recovery database exists, the role permission is enough or whether the SQL Server service is opened" & chr (13) & "information:" & Err.Description) Resume Next End Function Private Sub PBackup_complete (Byval Message As String) HA ndles 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 =

转载请注明原文地址:https://www.9cbs.com/read-105335.html

New Post(0)