Check file list inside a backup file

  • I'm trying to get the list of database names / files from a backup file. Here's the code:

    ''' <summary>

    ''' Prepare a RESTORE2 object.

    ''' </summary>

    Private Shared Function CreateRestoreObject(filePath As String, Optional forRestore As Boolean = False) As SQLDMO.Restore2

    Dim res As New SQLDMO.Restore2()

    ' What to restore

    res.Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database

    ' Input data

    res.Files = "[" + filePath + "]"

    ' Protection (?) password

    res.Password = SLQBackupPassword

    If forRestore Then

    res.ReplaceDatabase = True

    res.PercentCompleteNotification = 10

    End If

    Return res

    End Function

    Dim objRestore = CreateRestoreObject(filePath)

    Dim hdrList = objRestore.ReadBackupHeader(srv)

    Dim nameList = GetQueryResultList(hdrList, "DatabaseName")

    The code works fine on a SQL Server backup, but fails with a "***Password protected***" string on SQL Server Express backups. The corresponding SQL statement

    RESTORE HEADERONLY FROM DISK = N'...' WITH FILE = 1, NOUNLOAD , PASSWORD = N'...' works correctly. What am I doing wrong?

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply