?? backupdb.vb
字號:
Public Class BackUpDB
'備份數據庫
Public Shared Sub DBBackUp(ByVal prb As ProgressBar)
Dim bkps As New SQLDMO.Backup
Dim oSqlserver As New SQLDMO.SQLServer
Try
oSqlserver.LoginSecure = False
oSqlserver.Connect("(local)", "sa", "12345cc") '連接服務器
bkps = CreateObject("SQLDMO.Backup")
bkps.Database = "bssSystem" '指定需備份的數據庫
bkps.Action = 0
bkps.Files = "C:\bssSystem.bak" '指定備份文件
bkps.Initialize = True
prb.Value = 0
prb.Maximum = 100
Application.DoEvents()
Dim mouseCur As Cursor
bkps.SQLBackup(oSqlserver)
prb.Value = 100
Application.DoEvents()
bkps = Nothing
MsgBox("數據庫備份完成,保存在C:\bssSystem.bak", MsgBoxStyle.Information, "系統消息")
Catch ex As Exception
MessageBox.Show(ex.Message, "錯誤")
Finally
oSqlserver.DisConnect()
End Try
End Sub
'還原數據庫
Public Shared Sub DbRestore(ByVal prb As ProgressBar, ByVal path As String)
Dim oRestore As New SQLDMO.Restore
Dim oSQLServer As New SQLDMO.SQLServer
Try
oSQLServer.LoginSecure = False
oSQLServer.Connect("(local)", "sa", "12345cc")
oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
oRestore.Database = "bssSystem"
oRestore.Files = path
oRestore.FileNumber = 1
oRestore.ReplaceDatabase = True
prb.Value = 0
prb.Maximum = 100
Application.DoEvents()
Dim mouseCur As Cursor
oRestore.SQLRestore(oSQLServer)
prb.Value = 100
Application.DoEvents()
oRestore = Nothing
MsgBox("數據庫還原完成", MsgBoxStyle.Information, "系統消息")
Catch ex As Exception
MessageBox.Show(ex.Message, "錯誤")
Finally
oSQLServer.DisConnect()
End Try
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -