This project is read-only.

Cannot abort the Restore DB

Mar 12, 2012 at 12:19 PM
Edited Mar 13, 2012 at 11:12 AM

I would like to provide the user with the Cancel button - to abort a restore in progress. To do this, in the Restore.PercentComplete event handler I check if the user have clicked the Cancel button and call the Restore.Abort(). But this does not help:

The SMO throws exception:

Restore failed for Server 'MICHAEL7'. An exception occurred while executing a Transact-SQL statement or batch.
Stack Trace:   at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)

The DB stays in the "Restoring" mode forever. Here is the relevant code: 

using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

private volatile bool _CancelRestore = false;
private Restore _RestoreDB;
private Server _myServer;
private Database _currentDatabase;

// user hit Cancel buttton
public void CancelRestore()
    _CancelRestore = true;

// Restore.PercentComplete event handler
private static void CompletionStatusInPercent(object sender, PercentCompleteEventArgs args) 
    if (_CancelRestore)

        // Disable the kills to let some time to Abort()

        // Stop all processes running on the _currentDatabase database
        // _myServer.KillAllProcesses(_currentDatabase.Name);

        // Stop the _currentDatabase database
        // NOTE: it is a temp name DB: I do not restore over my application DB!
        // _myServer.KillDatabase(_currentDatabase.Name);
        Console.WriteLine("Percent completed: {0}%.", args.Percent);

The Backup/Restore functionality was implemented with the help of this article: SQL Server 2005 Database Backup and Restore using C# and .NET 2.0


Mar 17, 2012 at 7:54 AM

I am using PhpMyadmin to do my database works :)

Amazons Best Products Skynet Forum Cheap Carpets Legato Carpet Tiles Carpet Pricing Carpet Tiles Cheap