| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 917 人关注过本帖
标题:求助:数据库还原的问题
取消只看楼主 加入收藏
ruijian1227
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2005-4-22
收藏
 问题点数:0 回复次数:1 
求助:数据库还原的问题
从网上下载了一段数据库还原的代码,如下:

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

但是引用该函数之后,什么也没发生,数据库中没有任何的改变,请高手帮忙看看问题在哪里啊!
搜索更多相关主题的帖子: 数据库 ByVal Optional iDb ADODB 
2005-05-07 14:21
ruijian1227
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2005-4-22
收藏
得分:0 
你说的sqldemo能写成vb类模块,然后还原么?我是新手,做毕业设计要用,请多多执教,万分感激
2005-05-07 23:34
快速回复:求助:数据库还原的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033786 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved