📄 frmrecover.vb
字号:
Imports System.Data
Imports System.Data.sqlclient
Public Class frmrecover
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents bncancel As System.Windows.Forms.Button
Friend WithEvents bnbegin As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents tbpath As System.Windows.Forms.TextBox
Friend WithEvents dlgpath As System.Windows.Forms.OpenFileDialog
Friend WithEvents bnpath As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents tbname As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmrecover))
Me.bncancel = New System.Windows.Forms.Button
Me.bnbegin = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.bnpath = New System.Windows.Forms.Button
Me.tbpath = New System.Windows.Forms.TextBox
Me.dlgpath = New System.Windows.Forms.OpenFileDialog
Me.Label2 = New System.Windows.Forms.Label
Me.tbname = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'bncancel
'
Me.bncancel.Location = New System.Drawing.Point(232, 112)
Me.bncancel.Name = "bncancel"
Me.bncancel.TabIndex = 9
Me.bncancel.Text = "取消"
'
'bnbegin
'
Me.bnbegin.Location = New System.Drawing.Point(80, 112)
Me.bnbegin.Name = "bnbegin"
Me.bnbegin.TabIndex = 8
Me.bnbegin.Text = "开始恢复"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 64)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 23)
Me.Label1.TabIndex = 7
Me.Label1.Text = "备份文件路径:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'bnpath
'
Me.bnpath.Location = New System.Drawing.Point(304, 64)
Me.bnpath.Name = "bnpath"
Me.bnpath.TabIndex = 6
Me.bnpath.Text = "选择路径"
'
'tbpath
'
Me.tbpath.Location = New System.Drawing.Point(128, 64)
Me.tbpath.Name = "tbpath"
Me.tbpath.Size = New System.Drawing.Size(168, 21)
Me.tbpath.TabIndex = 5
Me.tbpath.Text = ""
'
'dlgpath
'
Me.dlgpath.Title = "选择备份文件路径"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 24)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(104, 23)
Me.Label2.TabIndex = 11
Me.Label2.Text = "还原数据库名称:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'tbname
'
Me.tbname.Location = New System.Drawing.Point(128, 24)
Me.tbname.Name = "tbname"
Me.tbname.Size = New System.Drawing.Size(168, 21)
Me.tbname.TabIndex = 10
Me.tbname.Text = ""
'
'frmrecover
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(400, 205)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.tbname)
Me.Controls.Add(Me.bncancel)
Me.Controls.Add(Me.bnbegin)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.bnpath)
Me.Controls.Add(Me.tbpath)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmrecover"
Me.Text = "----------数据库恢复"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub bnpath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnpath.Click
dlgpath.ShowDialog()
tbpath.Text = dlgpath.FileName
End Sub
Private Sub bnbegin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnbegin.Click
If tbname.Text = "" Then
MessageBox.Show("请输入备份文件路径")
Exit Sub
End If
If tbpath.Text = "" Then
MessageBox.Show("请输入备份文件路径")
Exit Sub
End If
Dim filepath = tbpath.Text.Trim()
'输入值完整并可用,插入记录到数据库
Dim strSource As String = " server=CHANGHAIFENG;uid=sa;pwd=;database=books"
'Dim strrecovery As String = "restore database books from disk='c:\data1' WITH REPLACE"
'Dim strrecovery As String = "restore database book from disk='" + filepath + "' WITH REPLACE"
Dim strrecovery As String = "restore database " + tbname.Text.Trim() + " from disk='" + filepath + "' WITH REPLACE"
Dim conn As New SqlConnection(strSource)
Try
conn.Open()
Dim cmd As New SqlCommand(strrecovery, conn)
Dim ret As Integer = cmd.ExecuteNonQuery()
If ret <> 1 Then
MessageBox.Show("还原成功!")
Else
MessageBox.Show("备份失败")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
conn.Close()
End Sub
Private Sub bncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bncancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -