C#
とは関係ありません。T-SQL
に関連しています。
T-SQL restore
では、バックアップセットから復元するファイルを定義できます。 WITH FILE=number_of_file
を使用すると簡単に定義できます。私も、この回避策を見てみることをお勧め
USE master;
--Create tail-log backup.
BACKUP LOG AdventureWorks2012
TO DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH NORECOVERY;
GO
--Restore the full database backup (from backup set 1).
RESTORE DATABASE AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=1,
NORECOVERY;
--Restore the regular log backup (from backup set 2).
RESTORE LOG AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=2,
NORECOVERY;
--Restore the tail-log backup (from backup set 3).
RESTORE LOG AdventureWorks2012
FROM DISK = 'Z:\SQLServerBackups\AdventureWorksFullRM.bak'
WITH FILE=3,
NORECOVERY;
GO
--recover the database:
RESTORE DATABASE AdventureWorks2012 WITH RECOVERY;
GO
:ここ
は、MSDNの記事
Complete Database Restores (Full Recovery Model)の例である
Restore a DB to the latest file in a backup set:
declare @dbname varchar(80),
@lastfull datetime,
@fullback varchar(1024),
@position int,
@SQL nvarchar(max)
set @dbname = 'YourDB'
select @lastfull = MAX(backup_finish_date)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.backupset b ON d.name = b.database_name AND b.type = 'D'
WHERE d.database_id NOT IN (2, 3) and [email protected]
SELECT @fullback = m.physical_device_name, @position = b.position
FROM msdb.dbo.backupmediafamily AS m INNER JOIN
msdb.dbo.backupset AS b ON m.media_set_id = b.media_set_id
and b.type='D' and [email protected]
AND [email protected]
set @SQL = 'RESTORE DATABASE [' + @DBname + '] FROM DISK = N''' + @fullback + ''' WITH FILE = ' + convert(nvarchar,@position) + ', RECOVERY, NOUNLOAD, STATS = 10'
EXEC SP_EXECUTESQL @SQL
[RESTORE(のTransact-SQL) ](https://msdn.microsoft.com/en-us/library/ms186858.aspx)を参照してください。これはC#と何が関係しているのか分かりません。 – Igor