“System.Data.SqlClient.SqlError: The operating system returned the error ‘5(Access is denied.)’ while attempting ‘RestoreContainer::ValidateTargetForCreation’ on ‘C:\Program Files\Microsoft SQL Server\MSSQLx.MSSQLSERVER\MSSQL\xxx.mdf’. (Microsoft.SqlServer.Smo)”
If you try to restore a backup file to a SQL Server Instance, you will see this error message if your SQL Server service does not have the required permissions to the folder that you want to restore the backup.
The SQL Server service performs the restoration of database backups. Restoring a backup file means that the SQL Server service will open your database files from the backup file to the destination folder. This means that your SQL Server service account must have write permissions in the destination folder where the database files will be created.
To do this, you must authorize the SQL Server service to write to the destination folder.
This solution worked successfully for me. Thanks for the details