备份数据库的代码,有问题,本人现在无法解决,请大家帮忙,具体问题写在下面.
问题说的简单点,就是能够备份数据库内容到指定文件中,但是在运行时会有错误产生.
下面是本人所写备份数据库代码(如下):
Private Sub xpcmdbutton1_Click()
Dim oSvr As SQLDMO.SQLserver
Set oSQLServer = CreateObject( "SQLDMO.SQLServer ")
oSQLServer.LoginSecure = False
oSQLServer.Connect "MS-12346546 ", "sa ", "15258646548 " '连接服务器
Screen.MousePointer = 11
Set bkps = CreateObject( "SQLDMO.Backup ")
bkps.Database = "Library " '指定需备份的数据库
bkps.Action = 0
bkps.Files = "d:\Library\DB.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 "数据库备份完成 ", vbOKOnly + vbInformation, "信息提示 "
End Sub
跳出窗口内容如下:
实时错误 '-2147221499(80040005) ':
[SQL-DMO]代码执行异常错误:EXCEPTION_ACCESS_VIOLATON
[解决办法]
数据库连接正确吗
[解决办法]
有很多这类问题已经解决的,找找看
我的做法:
cn为你要备份的数据联接
strsql = "Backup Database " & dbname & " to disk= ' " & path & "\ " & filename & ".bak ' with init "
Cn.Execute strsql