Introduction
In this article, we'll learn the best practices of moving a database to another physical location on the Server.
One of my friends was moving the database files to another location from the default location. He suddenly ran into an error stating, "Unable to Open the physical file "xxx" . Operating system error (Access is denied.) ".
This is an unexpected error on production server. When he asked me for help, I thought it would be good to share the solution with others too so that they can avoid this problem in their application.
The general recommendation is to keep database physical files on a different location from the default location . It would be better to separate the data and log files on different logical drives. It will boost the I/O operations.

Make sure that the new physical location of database has the required security permissions. That folder must have full control over the MSSQLSERVER service. If you do not give permission, it will throw an error "unable to open the physical file".
Take database to offline mode
Before starting the process, make sure that you have taken the database in offline mode. If you do not set it to offline mode, it may have data discrepancy to new database.
- ALTER DATABASE CopyMoveDBTest SET OFFLINE WITH ROLLBACK IMMEDIATE;
Alter the logical file path to new path
In this step, you have to modify the logical file path of .MDF , .NDF and .LDF files. Get the list of current logical names with path of database.
- USE master;
- GO
- -- Return the logical file name.
- SELECT name, physical_name AS CurrentLocation, state_desc
- FROM sys.master_files
- WHERE database_id = DB_ID(N'CopyMoveDBTest')




Yashwant VishwakarmaPosted May 22, 2017, 11:06 PM
Nice article brother :)
Upendra Pratap ShahiPosted May 22, 2017, 12:54 PM
Nice info shared...thanks for sharing...