strcon = "server=localhost;database=humanadministration;uid=cxl;pwd=cxl;"
con = New SqlConnection(strcon)
strsql = "backup database yourdatabase to disk='" & databasepath & "'"
com = New SqlCommand(strsql, con)
'数据库备份操作
Private Sub btnBackUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackUp.Click
Dim oSvr As SQLDMO.SQLServer
Dim oSQLServer As New SQLDMO.SQLServer()
oSQLServer.LoginSecure = False
oSQLServer.Connect("(local)", "sa", "sa") '连接服务器
Me.Cursor = Windows.Forms.Cursors.WaitCursor
bkps = CreateObject("SQLDMO.Backup")
bkps.Database = "Northwind" '指定需备份的数据库
bkps.Action = 0
bkps.Files = "f:\Northwind.bak" '指定备份文件
bkps.Initialize = True
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
Me.Cursor = Windows.Forms.Cursors.Default()
Application.DoEvents()
Dim mouseCur As Cursor
Me.Cursor = Windows.Forms.Cursors.WaitCursor
bkps.SQLBackup(oSQLServer)
ProgressBar1.Value = 100
Application.DoEvents()
bkps = Nothing
Me.Cursor = Windows.Forms.Cursors.Default()
MsgBox("数据库备份完成", MsgBoxStyle.Information, "系统消息")
End Sub
'显示进度
Private Sub bkps_PercentComplete(ByVal Message As String, ByVal Percent As Integer) Handles bkps.PercentComplete
ProgressBar1.Value = ProgressBar1.Maximum * (Percent / 100)
End Sub