主题:[求助]数据还原出错
做毕业设计时,需做到数据备份和数据还原,数据备份做好了,但是数据还原出错了问题,现在急需大家的帮忙,下面是代码和出错信息:
'实现数据备份
Dim obackup As New SQLDMO.Backup
Dim osqlserver As New SQLDMO.SQLServerClass
Try
osqlserver.LoginSecure = False
osqlserver.Connect("(local)", "sa", "")
obackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
obackup.Database = "you"
obackup.Files = "d:\you.bak"
obackup.BackupSetName = "you"
obackup.BackupSetDescription = "数据库备份"
obackup.Initialize = True
obackup.SQLBackup(osqlserver)
MsgBox("备份成功!!!")
Catch ex As Exception
MsgBox(ex.Message)
Finally
osqlserver.DisConnect()
End Try
数据还原:
Dim orestore As New SQLDMO.Restore
Dim osqlserver As New SQLDMO.SQLServerClass
Try
osqlserver.LoginSecure = False
osqlserver.Connect("(local)", "sa", "")
orestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
orestore.Database = "you"
orestore.Files = "d:\you.bak"
orestore.FileNumber = 1
orestore.ReplaceDatabase = True
orestore.SQLRestore(osqlserver)
MsgBox("还原成功!!!")
Catch ex As Exception
MsgBox(ex.Message)
Finally
osqlserver.DisConnect()
End Try
出错信息:因为数据库正在使用,所以未所获得对数据库的排它访问权.
这个月就要验收,请大家帮忙一下,急,谢谢!!!
'实现数据备份
Dim obackup As New SQLDMO.Backup
Dim osqlserver As New SQLDMO.SQLServerClass
Try
osqlserver.LoginSecure = False
osqlserver.Connect("(local)", "sa", "")
obackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database
obackup.Database = "you"
obackup.Files = "d:\you.bak"
obackup.BackupSetName = "you"
obackup.BackupSetDescription = "数据库备份"
obackup.Initialize = True
obackup.SQLBackup(osqlserver)
MsgBox("备份成功!!!")
Catch ex As Exception
MsgBox(ex.Message)
Finally
osqlserver.DisConnect()
End Try
数据还原:
Dim orestore As New SQLDMO.Restore
Dim osqlserver As New SQLDMO.SQLServerClass
Try
osqlserver.LoginSecure = False
osqlserver.Connect("(local)", "sa", "")
orestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database
orestore.Database = "you"
orestore.Files = "d:\you.bak"
orestore.FileNumber = 1
orestore.ReplaceDatabase = True
orestore.SQLRestore(osqlserver)
MsgBox("还原成功!!!")
Catch ex As Exception
MsgBox(ex.Message)
Finally
osqlserver.DisConnect()
End Try
出错信息:因为数据库正在使用,所以未所获得对数据库的排它访问权.
这个月就要验收,请大家帮忙一下,急,谢谢!!!