⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backupdb.vb

📁 本文件为进销存管理系统的代码 在VB的环境下运行 用比较简单的结构完成的
💻 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 + -