title: SMO "Restore failed for Server" Restoring Backup From File
body: <p>I'm using the following code to restore a backup sql database with C# and SMO.</p>
  
  <pre><code>void RestoreDatabaseWithSMO(string sConnect, string dbName, string backUpPath)
  {
      using (SqlConnection cnn = new SqlConnection(sConnect))
      {
          cnn.Open();
          cnn.ChangeDatabase("master");
  
          ServerConnection sc = new ServerConnection(cnn);
          Server sv = new Server(sc);
  
          if (!sv.Databases.Contains(dbName))
              throw new Exception("this DataBase does not exist");
  
          // Create backup device item for the backup
          BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File);
  
          // Create the restore object
          Restore resDB = new Restore();
          resDB.PercentComplete += new PercentCompleteEventHandler(percentComplete);
          resDB.PercentCompleteNotification = 10;
          resDB.Devices.Add(bdi);
          resDB.NoRecovery = false;
          resDB.ReplaceDatabase = true;
          resDB.Database = dbName;
          resDB.Action = RestoreActionType.Database;
  
          // Restore the database
          resDB.SqlRestore(sv);//Exception
      }
  }
  </code></pre>
  
  <p>but in the last line I got below exception !!!<br /></p>
  
  <pre><code>{"Restore failed for Server '\\\\.\\pipe\\3F103E6E-3FD4-47\\tsql\\query'. "}
  </code></pre>
  
  <p>What's wrong with it ?<br />
  Could you please guide me? thanks</p>