各位高人:
我想用用VB程序怎样还原数据库:我的代码是如下:
Private Sub mnurestore_Click()
On Error GoTo restoreerr
Dim strfile As String
Dim strfilename As String
Dim i As Double
CommonDialog1.DialogTitle = "select a file to restore"
CommonDialog1.ShowOpen
strfile = CommonDialog1.FileName
If Trim(strfile) = "" Then Exit Sub
For i = 1 To Len(strfile)
If mId(Right(strfile, i), 1, 1) = "\" Then
strfilename = Right(strfile, i - 1)
Exit For
End If
Next i
Dim strsql2 As String
Dim cmdrestore As ADODB.Command strsql2 = "RESTORE DATABASE feesys FROM " & strfilename '& '" WITH restricted_user,NORECOVERY"
gAdoConnect.Close
Set gAdoConnect = Nothing
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "dsn=feesysdb;uid=sa;pwd=;"
Set cmdrestore = New ADODB.Command
Set cmdrestore.ActiveConnection = cn cmdrestore.CommandText = strsql2
cmdrestore.Execute
MsgBox "恢复成功!"
ConnectDB
Exit Sub但是 老提示如下错误:
数据库正在使用,所以未能获得数据库的排它访问权
诚恳各位相助!!!!!!!!!!!!!!!!
我想用用VB程序怎样还原数据库:我的代码是如下:
Private Sub mnurestore_Click()
On Error GoTo restoreerr
Dim strfile As String
Dim strfilename As String
Dim i As Double
CommonDialog1.DialogTitle = "select a file to restore"
CommonDialog1.ShowOpen
strfile = CommonDialog1.FileName
If Trim(strfile) = "" Then Exit Sub
For i = 1 To Len(strfile)
If mId(Right(strfile, i), 1, 1) = "\" Then
strfilename = Right(strfile, i - 1)
Exit For
End If
Next i
Dim strsql2 As String
Dim cmdrestore As ADODB.Command strsql2 = "RESTORE DATABASE feesys FROM " & strfilename '& '" WITH restricted_user,NORECOVERY"
gAdoConnect.Close
Set gAdoConnect = Nothing
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "dsn=feesysdb;uid=sa;pwd=;"
Set cmdrestore = New ADODB.Command
Set cmdrestore.ActiveConnection = cn cmdrestore.CommandText = strsql2
cmdrestore.Execute
MsgBox "恢复成功!"
ConnectDB
Exit Sub但是 老提示如下错误:
数据库正在使用,所以未能获得数据库的排它访问权
诚恳各位相助!!!!!!!!!!!!!!!!
解决方案 »
- 如何用vb查看当前打开的IE网页中是否包含特定文字
- [DBNETLIB][ConnectionOpen (Connect()).]SQL Server 不存在或拒绝访问
- VB数组,一个简单而又奇怪的问题?
- 高手帮帮忙!
- 代码共享】关于Win2K/NT/XP环境下LWIN,RWIN,WIN+Any,Ctrl+Esc,Alt+Esc,Alt+TAB等键的禁用
- 急...在线等待,请帮忙)我想调用一个包含公式的acess数据库利用另一个数据库的数据计算结果,但公式数据库的公式数据类型是文本,因此无法识
- 有关软件界面设计的问题
- 文字识别,在线求助!
- 求大家帮忙!怎么实现视频的动态伪彩!???
- 如何取消上一次的操作?(如误删了一条记录,想恢复!)
- 急!SQL Server还原问题,高手请进!
- VB备份SQL Server数据库以后,还原数据库该如何实现?
Dim newMdb As String
Dim SHFileOp As SHFILEOPSTRUCT SHFileOp.wFunc = FO_COPY
SHFileOp.pFrom = App.Path & "\back\msDATAformobile.mdb"
SHFileOp.pTo = App.Path & "\msDATAformobile.mdb"
SHFileOp.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMMKDIR
Call SHFileOperation(SHFileOp) MsgBox "复原已完成!" Exit Sub
i = MsgBox("恢复数据库操作将覆盖现有的数据,是否恢复?", 4 + 32)
If i = 7 Then Exit Sub
If Dir(strfilename) = "" Then
MsgBox "备份文件<" & strfilename & ">不存在,请重新输入!": Exit Sub
End If
Dim oSvr As SQLDMO.SQLServer
On Error Resume Next
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
If Err > 0 Then
If Err = 429 Then
MsgBox "请首先安装 MSDE": Exit Sub
End If
End If
oSQLServer.LoginSecure = False
oSQLServer.Connect "dsn=feesysdb;uid=sa;pwd=;"
If Err <> 0 Then
MsgBox "连接 SQLServer 不成功,请首先登录 SQLServer": Exit Sub
End If
Err = 0
Set stos = CreateObject("SQLDMO.Restore")
stos.Action = SQLDMORestore_Database
stos.Database = "feesysdb"
stos.ReplaceDatabase = True
stos.Files = strfilename
Screen.MousePointer = 11
DoEvents
On Error Resume Next
stos.SQLRestore oSQLServer
On Error GoTo 0
Screen.MousePointer = 0
DoEvents
Set stos = Nothing
MsgBox "数据库恢复完成"
我的代码在SQLSERVER 7.0上好使 但在数据库SQLSERVER 2000 上不好使 你的代码在
Dim oSvr As SQLDMO.SQLServer 各块出错 无法定义
microsoft SQLDMO object library
在引用中添加microsoft SQLDMO object library就可以了.