2
I am backing up and re-storing an SQL Server database using the C# NET Backup and Restore classes with Smo.
The problem is that after backing up the database with the name, for example "Test", I cannot restore the database with another name, which is possible using tools such as Management Studio. It would be possible to restore the database with another name through the Restore class?
public void Restore(String dataBaseName, pathFile)
{
bdi = default(BackupDeviceItem);
bdi = new BackupDeviceItem(pathFile, DeviceType.File);
Restore rs = new Restore();
rs.NoRecovery = false;
rs.SqlVerify(srv);
rs.Devices.Add(bdi);
rs.Database = dataBaseName;
rs.SqlRestore(srv);
rs.Devices.Remove(bdi);
}
You can put an example of your code in your question?
– Leonel Sanches da Silva
Try changing the database name when backing up, not Restore. If it works, I put it in answer.
– Leonel Sanches da Silva
I thought about doing this, but if I put in time to take the backup it will not find the bank to copy.
– Murilo Fechio
I’ve done it but not with the Restore class but with Sqlcommand and sqlDataAdapt running an SQL to restore.
– rubStackOverflow