Метод Restore.ReadBackupHeader
Reads the backup header and returns information about the media contents.
Пространство имен: Microsoft.SqlServer.Management.Smo
Сборка: Microsoft.SqlServer.SmoExtended (в Microsoft.SqlServer.SmoExtended.dll)
Синтаксис
'Декларация
Public Function ReadBackupHeader ( _
srv As Server _
) As DataTable
'Применение
Dim instance As Restore
Dim srv As Server
Dim returnValue As DataTable
returnValue = instance.ReadBackupHeader(srv)
public DataTable ReadBackupHeader(
Server srv
)
public:
DataTable^ ReadBackupHeader(
Server^ srv
)
member ReadBackupHeader :
srv:Server -> DataTable
public function ReadBackupHeader(
srv : Server
) : DataTable
Параметры
- srv
Тип: Microsoft.SqlServer.Management.Smo.Server
A Server object that represents the instance of SQL Server that provides access to the targeted media.
Возвращаемое значение
Тип: System.Data.DataTable
A DataTable object that specifies information about the media contents.
Замечания
For information about the media contents, see, see Инструкция RESTORE HEADERONLY (Transact-SQL).
Примеры
The following code example demonstrates how to create a backup, associate it with an instance of the restore class, and use the ReadBackupHeader method to display information about the restore media contents.
VB
Dim srv As Server = New Server()
Dim res As Restore = New Restore()
Dim backup As Backup = New Backup()
Dim dt As DataTable
backup.Devices.AddDevice("C:\AdventureWorks2012Backup.bak", DeviceType.File)
backup.Database = "AdventureWorks2012"
backup.Action = BackupActionType.Database
backup.Initialize = True
backup.SqlBackup(srv)
res.Devices.AddDevice("C:\AdventureWorks2012Backup.BAK", DeviceType.File)
dt = res.ReadBackupHeader(srv)
For Each r As DataRow In dt.Rows
For Each c As DataColumn In dt.Columns
Console.WriteLine(c.ToString + " = " + r(c).ToString())
Next
Next
PowerShell
$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$res = new-object Microsoft.SqlServer.Management.Smo.Restore
$backup = new-object Microsoft.SqlServer.Management.Smo.Backup
$backup.Devices.AddDevice("C:\AdventureWorks2012Backup.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$backup.Database = "AdventureWorks2012"
$backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$backup.Initialize = $TRUE
$backup.SqlBackup($srv)
$res.Devices.AddDevice("C:\AdventureWorks2012Backup.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$dt = $res.ReadBackupHeader($srv)
foreach($r in $dt.Rows)
{
foreach ($c in $dt.Columns)
{
Write-Host $c "=" $r[$c]
}
}
См. также
Справочник
Пространство имен Microsoft.SqlServer.Management.Smo
Другие ресурсы
Резервное копирование и восстановление баз данных SQL Server