Welcome to Sign in | Help

Re: SMO Issue

  •  10-26-2007, 11:01 AM

    Re: SMO Issue

    Private Function ExecuteDBRestore(ByVal DBName As String, _
                                          ByVal BackupPath As String, _
                                          ByVal RestorePath As String) As Boolean

            Dim bResult As Boolean = True
            Dim restore As Restore = Nothing

            Try
                Dim conn As ServerConnection = New ServerConnection(SQLServerName, UserName, Passwd)
                conn.ConnectTimeout = 10000

                Dim srv As Server = New Server(conn)
                Dim db As Database = srv.Databases(DBName)

                If Not db Is Nothing Then srv.KillAllProcesses(DBName)

                restore = New Restore()
                restore.Action = RestoreActionType.Database
                restore.Database = DBName
                restore.Devices.AddDevice(BackupPath, DeviceType.File)
                restore.NoRecovery = True
                restore.ReplaceDatabase = True
                restore.NoRewind = True

                Dim DBLogicalFile As String = restore.ReadFileList(srv).Rows(0)(0) ' for AAIA db is VCDB_Public
                Dim DBLogLogicalFile As String = restore.ReadFileList(srv).Rows(1)(0) ' for AAIA db is VCDB_Public_Log
                restore.RelocateFiles.Add(New RelocateFile(DBLogicalFile, Path.Combine(RestorePath, DBName & "_Data.mdf")))
                restore.RelocateFiles.Add(New RelocateFile(DBLogLogicalFile, Path.Combine(RestorePath, DBName & "_Log.ldf")))

                restore.SqlRestore(srv)
                restore.UnloadTapeAfter = True

                db = srv.Databases(DBName)
                db.SetOnline()

            Catch ex As Exception
                bResult = False
            Finally
                If Not restore Is Nothing Then
                    restore.Devices.Clear()
                End If
            End Try

            Return bResult
        End Function

    In urmatorul exemplu (http://msdn2.microsoft.com/en-us/library/ms162166.aspx) apare:

    Dim rs As Restore
    rs = New Restore
    'Set the NoRecovery property to true, so the transactions are not recovered.
    rs.NoRecovery = True


    Poate problema dvs e la linia restore.NoRecovery = True


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems