VB.NET DMO SQL Server Backup Recovery

xiaoxiao2021-03-06  87

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. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting disposal to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer

'Note: The following procedure is necessary 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

Since the trouble is not dealt with by the property ... should be improved by the 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 Withevent ORESTORE As New SqldMo.restore ()

'Property SQLServername () AS String' Get 'Return Sql Server' 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 function

Errhandler:

Msgbox ("Backup failed, please check if the source database exists, if the role permission is enough or whether the SQL Server service is opened" & 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)

Orentore.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) Handles PBackup.comPlete

Me.ProgressBar1.Value = 100 pBackup = Nothing me.orestore = Nothing me.close ()

End Sub Private Sub PBackup_PerCentComplete (Byval Message As "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 Outue_complete (Byval Message As String) Handles Orentore.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. OlivedRabme.ProgressBar1.Value = percentiff if percent = 100 Then

Me.ProgressBar1.Value = 100 pBackup = Nothing me.orestore = Nothing me.close () end if End Sub

Private sub button1_click (byvale) Handles button1.click if flag = true kil

Me.Backup (Me.Database, Me.Sqlserver, Me.SA, Me.Passerd, Me.File)

Else Me.rs (me.database, me.sqlserver, me.sa, me.passerd, me.file)

END IF

End Sub

END CLASS

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

New Post(0)