title: SQL Server Restore using T-SQL - error '5(error not found)'
body: <p>To restore a database data and log files to different drives I am running the following T-SQL:</p>
  
  <pre><code>RESTORE DATABASE DbName_BLAH
  FROM DISK = 'w:\temp\DbName.bak'
  WITH MOVE 'DbName' TO 'm:\DbName_BLAH.mdf',
  MOVE 'DbName_log' TO 'l:\DbName_BLAH_log.ldf'
  </code></pre>
  
  <p>And receiving the following errors:</p>
  
  <blockquote>
    <p>Msg 3634, Level 16, State 1, Line 16
    The operating system returned the
    error '5(error not found)' while
    attempting
    'RestoreContainer::ValidateTargetForCreation'
    on 'm:\DbName_BLAH.mdf'. Msg 3156,
    Level 16, State 5, Line 16 File
    'DbName' cannot be restored to
    'm:\DbName_BLAH.mdf'. Use WITH MOVE to
    identify a valid location for the
    file. Msg 3634, Level 16, State 1,
    Line 16 The operating system returned
    the error '5(error not found)' while
    attempting
    'RestoreContainer::ValidateTargetForCreation'
    on 'l:\DbName_BLAH_log.ldf'. Msg 3156,
    Level 16, State 5, Line 16 File
    'DbName_log' cannot be restored to
    'l:\DbName_BLAH_log.ldf'. Use WITH
    MOVE to identify a valid location for
    the file. Msg 3119, Level 16, State 1,
    Line 16 Problems were identified while
    planning for the RESTORE statement.
    Previous messages provide details. Msg
    3013, Level 16, State 1, Line 16
    RESTORE DATABASE is terminating
    abnormally.</p>
  </blockquote>
  
  <p>The database restores as expected when I execute:</p>
  
  <pre><code>RESTORE DATABASE DbName_BLAH
  FROM DISK = 'w:\temp\DbName.bak'
  WITH MOVE 'DbName' TO 'w:\temp\DB_BLAH.mdf',
  MOVE 'DbName_log' TO 'w:\temp\DbName_BLAH_log.ldf'
  </code></pre>
  
  <p>I have checked permissions on M: and L:. Any ideas?</p>
  
  <p><strong>UPDATE:</strong> Permissions were given to the SQL Server login rather than the SQL Server service account. See answer below.</p>