title: Restore Database "Restore failed for Server 'xxx' "
body: <p>I have a problem. I tried the code like belov. But i am getting exception. and the exception is : </p>
  
  <pre><code>"Restore failed for Server 'SMART0090\SQL2008RR2'."  FailedOperationException. .... the error is at "restore.SqlRestore(server);" line
  </code></pre>
  
  <p>What do you think about the problem? The code is : </p>
  
  <pre><code>public void RestoreToDatabase(string NewDatabaseName, string BackUpFile, string ServerName, string UserName, string Password)
      {
          ServerConnection connection = new ServerConnection(ServerName, UserName, Password);
          Server sqlServer = new Server(connection);
          Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(connection);
          Database database = new Database(server, NewDatabaseName);
          database.Create();
  
          database.Refresh();
  
          Restore restore = new Restore();
  
          restore.NoRecovery = false;
  
          restore.Action = RestoreActionType.Database;
  
          BackupDeviceItem bdi = default(BackupDeviceItem);
  
          bdi = new BackupDeviceItem(BackUpFile, DeviceType.File);
  
          restore.Devices.Add(bdi);
  
          restore.Database = NewDatabaseName;
  
          restore.ReplaceDatabase = true;
  
          restore.PercentCompleteNotification = 10;
  
          restore.SqlRestore(server);
  
          database.Refresh();
  
          database.SetOnline();
  
          server.Refresh();
      } 
  </code></pre>
  
  <p>EDIT : All exception message is just this : <img src="https://i.stack.imgur.com/11otv.png" alt="enter image description here"></p>
  
  <p>Thanks For your advice....</p>