I'm trying to restore a SQL database backup with this code
private void btnRestore_Click(object sender, EventArgs e)
{
string dbName = "BakodahDB";
try
{
Server dbServer = new Server(); //local using windows athuentication
Restore dbRestore = new Restore() { Database = dbName, Action = RestoreActionType.Database, ReplaceDatabase = true, NoRecovery = false };
dbRestore.Devices.AddDevice(@"C:\WorkHours\dbBackup.bak", DeviceType.File);
dbRestore.PercentComplete += DbRestore_PercentComplete;
dbRestore.Complete += DbRestore_Complete;
dbRestore.SqlRestoreAsync(dbServer);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
When I click the button nothing happens, not even an error message... What's the right way to do it?
I just needed to kill all process before restoring
it worked!