I have an application used to manage databases to demonstrate our software, one of the things it does is to get a copy of the database from a central server and restore it to a local SQL instance. Everything works correctly on the backup part, but during recovery, some people report that they receive the next exception in the middle of recovery.
Microsoft.SqlServer.Management.Smo.FailedOperationException: Restore failed for Server 'Computername'.
An exception occurred while executing a Transact-SQL statement or batch.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
(snip)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
(snip)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at ContractFlowTool.WebInfinity2.AttachDatabase.RestoreLocal(AttachDatabaseArgs arg)
MSDN is lightweight enough for the internal workings of SMO classes. I could not find any way to change the timeout for the restore. What can I do, exception will not happen?
Here is the code that performs the recovery
private static bool RestoreLocal(AttachDatabaseArgs arg)
{
if (arg.DestDatabase == null)
throw new ArgumentNullException("DestDatabase");
SqlConnectionInfo serverConnInfo = new SqlConnectionInfo();
ServerConnection serverConn = null;
serverConn = new ServerConnection(serverConnInfo);
var remoteServer = new Server(serverConn);
var clinicFolder = ClinicFolder(arg);
var restore = new Restore();
restore.PercentCompleteNotification = 5;
restore.NoRecovery = false;
restore.RelocateFiles.Add();
restore.RelocateFiles.Add();
restore.Database = arg.LocalDB;
restore.ReplaceDatabase = true;
restore.Action = RestoreActionType.Database;
restore.PercentComplete += arg.ProgressForm.Restore_PercentComplete;
restore.SqlRestore(remoteServer);
}