Hi,
My problem is really simple. I have a .bak file that contains one or more backup set.
When I'm using SMO to restore the database with this .bak file, it only takes the first backup set to do its work. It seems to ignore the remaining sets.
Why's that ?
See my code :
//Sets the restore configuration
Restore restore = new Restore()
{
Action = RestoreActionType.Database,
Database = _databaseToRestore.DatabaseName,
ReplaceDatabase = true
};
restore.Devices.Add(new BackupDeviceItem(_backupFilePath, DeviceType.File));
Server server = new Server(_databaseToRestore.ServerName);
DataTable fileList = restore.ReadFileList(server);
string serverDataFolder = server.Settings.DefaultFile;
if (string.IsNullOrEmpty(serverDataFolder))
serverDataFolder = server.Information.MasterDBPath;
foreach (DataRow file in fileList.Rows)
{
restore.RelocateFiles.Add(
new RelocateFile((string)file["LogicalName"],
Path.Combine(serverDataFolder, _databaseToRestore.DatabaseName + Path.GetExtension((string)file["PhysicalName"]))));
}
//Gets the exclusive access to database
server.KillAllProcesses(_databaseToRestore.DatabaseName);
restore.Wait();
restore.SqlRestore(server);
I thought the BackupDeviceItem could gives me a feedback on how many backup sets there's inside, this way I could warn the user, but it's not.
Anyone has a clue on this ?
Thanks for your time.