本人用的是记录集,想实现数据备份,但是弄了半天还是出错,但是会成一个.bak的备份文件,出错代码和出错信息如下:请赐教错在哪里?谢谢!
Public WithEvents bkps As SQLDMO.Backup
'数据库备份操作
Private Sub Command1_Click()
Dim oSvr As SQLDMO.SQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.LoginSecure = False
oSQLServer.Connect "(local)", "sa", "sa" '连接服务器
Screen.MousePointer = 11
Set bkps = CreateObject("SQLDMO.Backup")
bkps.Database = "学生学籍管理" '指定需备份的数据库
bkps.Action = 0
bkps.Files = "E:\数据备份\学生学籍管理.bak" '指定备份文件
bkps.Initialize = True
ProgressBar1.Value = 0
ProgressBar1.Max = 100
Screen.MousePointer = 0
DoEvents
Err = 0
bkps.SQLBackup (oSQLServer)
Screen.MousePointer = 11
ProgressBar1.Value = 100
DoEvents
Set bkps = Nothing
Screen.MousePointer = 0
MsgBox "数据库备份完成"
End Sub
'显示进度
Private Sub bkps_PercentComplete(ByVal Message As String, ByVal Percent As Long)
ProgressBar1.Value = ProgressBar1.Max * (Percent / 100)
End Sub
出错提示:
实时错误'-2147221499(80040005)
[SQL-DMO]代码异常错误:EXCEPTION_ACCESS_VIOLATION