Moving SQL Server Database Files to New Location - Why permission error? I was trying to move a database (.mdf and .ldf files) to a different directory on the same server hosting the SQL server.  I followed these steps found in this Q&amp;A:


ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
ALTER DATABASE MyDB SET OFFLINE  
ALTER DATABASE MyDB MODIFY FILE (Name = MyDB, Filename = 'N:\DATA\MyDB.MDF')
ALTER DATABASE MyDB SET ONLINE
ALTER DATABASE MyDB SET MULTI_USER


When I got to Step4, I got "Access Denied".  Unfortunately, my maintenance windows were very short and no time to troubleshoot.  So I decided to drop the database and restored it using the WITH MOVE clause to place the DB files in the right directory.  No issue.  

My question is why did I get "Access Denied"?  I didn't change MSSQL service account.  It's the same account that ran the RESTORE.
The ALTER DATABASE MyDB MODIFY FILE (Name = MyDB, Filename = 'N:\DATA\MyDB.MDF') statement doesn't actually move the files.  It merely moves the definition of where the files reside.  You'd need to actually move the files manually before continuuing to step 4.

When you move the files prior to step 4, you must ensure the target directory has the correct permissions for the SQL Serve service account.  This document details the requirements.