The following references need to be added

Microsoft.SqlServer.Smo
Microsoft.SqlServer.SmoEnum
Microsoft.SqlServer.ConnectionInfo



ServerConnection oCon = new ServerConnection(server, DBUserID, DBPassword);

Server oServer = new Server(oCon);
Restore oRestore = new Restore();

//sFileName - File Physical Location

if (File.Exists(sFileName))
{
oRestore.Database = DbName;
oRestore.Action = RestoreActionType.Database;
oRestore.Devices.AddDevice(sFileName, DeviceType.File);
oRestore.NoRecovery = false;
oRestore.ReplaceDatabase = true;
oRestore.PercentCompleteNotification = 10;
oRestore.PercentComplete +=
new PercentCompleteEventHandler(bkp_percentComplete);
oRestore.SqlRestore(oServer);
}

protected void bkp_percentComplete(object sender, PercentCompleteEventArgs e)
{
lblStatus.Text = e.Percent.ToString() + "% restored";
}

Category : | Read More......