求助:数据库还原的问题
从网上下载了一段数据库还原的代码,如下:Public Function fRestoreDatabase_a(ByVal sBackUpfileName$ _
, ByVal sDataBaseName$ _
, Optional ByVal sDataBasePath$ = "" _
, Optional ByVal sBackupNumber& = 1 _
, Optional ByVal sReplaceExist As Boolean = False _
) As String
Dim iDb As ADODB.Connection, ire As ADODB.Recordset
Dim iConcStr$, isql$, iReturn$, iI&
Dim username As String
Dim userpsw As String
Dim dbname As String
Dim hostname As String
Dim filename
filename = FreeFile
Open "d:\dbconnect.ini" For Input As filename
Input #filename, username, userpsw, dbname, hostname
On Error GoTo lbErr
'创建对象
Set iDb = New ADODB.Connection
Set ire = New ADODB.Recordset
'连接数据库服务器,根据你的情况修改连接字符串
iConcStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;User ID ='" & username & "';Password='" & userpsw & "';Initial Catalog= '" & dbname & "';Persist Security Info=False;Data Source= '" & hostname & "'"
iDb.Open iConcStr
'得到还原后的数据库存放目录,如果没有指定,存放到SQL SERVER的DATA目录
If sDataBasePath = "" Then
isql = "select filename from master..sysfiles"
ire.Open isql, iDb, adOpenKeyset, adLockReadOnly
isql = ire(0)
ire.Close
sDataBasePath = Left(isql, InStrRev(isql, "\"))
End If
'检查数据库是否存在
If sReplaceExist = False Then
isql = "select 1 from master..sysdatabases where name= & sDataBaseName & "
ire.Open isql, iDb, adOpenKeyset, adLockReadOnly
If ire.EOF = False Then
iReturn = "数据库已经存在"
ire.Close
GoTo lbExit
End If
ire.Close
Set ire = Nothing
End If
'关闭用户进程,防止其它用户正在使用数据库,导致数据恢复失败
isql = "select spid from master..sysprocesses where dbid=db_id('" & sDataBaseName & "')"
ire.Open isql, iDb, adOpenKeyset, adLockReadOnly
While ire.EOF = False
isql = "kill " & ire(0)
iDb.Execute isql
ire.MoveNext
Wend
ire.Close
iDb.Close
'获取数据库恢复信息
isql = "restore filelistonly from disk='" & sBackUpfileName & "'" & vbCrLf & _
"with file=" & sBackupNumber
ire.Open isql, iDb, adOpenKeyset, adLockReadOnly
'生成数据库恢复语句
isql = "restore database '" & sDataBaseName & " 'from disk= '" & sBackUpfileName & " with file = ' " & sBackupNumber & "'"
iDb.Execute isql
iReturn = ""
iDb.Close
ire.Close
GoTo lbExit
lbErr:
iReturn = Error
Exit Function
lbExit:
fRestoreDatabase_a = iReturn
End
End Function
但是引用该函数之后,什么也没发生,数据库中没有任何的改变,请高手帮忙看看问题在哪里啊!