title: SQL Server: Database stuck in "Restoring" state
body: <p>I backed up a database:</p>
  
  <pre><code>BACKUP DATABASE MyDatabase
  TO DISK = 'MyDatabase.bak'
  WITH INIT --overwrite existing
  </code></pre>
  
  <p>And then tried to restore it:</p>
  
  <pre><code>RESTORE DATABASE MyDatabase
     FROM DISK = 'MyDatabase.bak'
     WITH REPLACE --force restore over specified database
  </code></pre>
  
  <p>And now the database is stuck in the restoring state.</p>
  
  <p>Some people have theorized that it's because there was no log file in the backup, and it needed to be rolled forward using:</p>
  
  <pre><code>RESTORE DATABASE MyDatabase
  WITH RECOVERY 
  </code></pre>
  
  <p>Except that, of course, fails:</p>
  
  <pre><code>Msg 4333, Level 16, State 1, Line 1
  The database cannot be recovered because the log was not restored.
  Msg 3013, Level 16, State 1, Line 1
  RESTORE DATABASE is terminating abnormally.
  </code></pre>
  
  <p>And exactly what you want in a catastrophic situation is a restore that won't work.</p>
  
  <hr>
  
  <p>The backup contains both a data and log file:</p>
  
  <pre><code>RESTORE FILELISTONLY 
  FROM DISK = 'MyDatabase.bak'
  
  Logical Name    PhysicalName
  =============   ===============
  MyDatabase    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase.mdf
  MyDatabase_log  C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\MyDatabase_log.LDF
  </code></pre>