Unable to open the physical file. Operating system error 5: “5(Access is denied.)”

Nishant Kumar 1 Reputation point
2020-09-24T01:18:45.57+00:00

I am trying to work on a query to attach a database (UNC path) remotely. I have SQL Server management studio (SSMS) installed in SQL Server machine (machineSQL) and also in another machine (machineRemote) in same domain.

Query::

CREATE DATABASE "simpleData" ON 
(FILENAME = '\\machineRemote\ShareName\sample\sample_database.mdf'),
(FILENAME = '\\machineRemote\ShareName\sample\sample_database_log.ldf')
FOR ATTACH;

If I run the query in SSMS on machineSQL. The database gets attached successfully. But if I run it in SSMS on machineRemote it throws an error like :

Msg 5120, Level 16, State 101, Line 1
Unable to open the physical file "\\machineRemote\ShareName\sample\sample_database.mdf". Operating system error 5: "5(Access is denied.)".
Msg 1802, Level 16, State 7, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

NOTE : The issue is occurring only if windows authentication is used to log in SSMS. SQL Server authentication works just fine. I have tried domain user permission on the database file path and also tried running SQL Server services as domain user, still no luck.

Need help on this.

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

8 answers

Sort by: Most helpful
  1. Olaf Helper 47,541 Reputation points
    2023-06-05T08:02:24.9+00:00

    (FILENAME = '**\machineRemote**ShareName\sample\sample_database.mdf

    It's not supported to host database files on a NAS.

    It may work, but the smallest network hickup and the database file(s) may get damaged.

    0 comments No comments

  2. Ela Salimi 0 Reputation points
    2023-07-18T05:58:44.1433333+00:00

    My problem was in the file stream backup restore, which I fixed below5.png

    2-----Acsess Full user MSSQLSERVER to Folder And User LOCAL

    Finally : Disable Anti Viruse

    5

    0 comments No comments

  3. Bruce (SqlWork.com) 79,101 Reputation points Volunteer Moderator
    2025-05-17T18:42:24.1733333+00:00

    Typically the Sqlserver service account is a local account which does not have network access permissions. You need to change the service account to a domain account and give the domain account permissions to the file share.

    be aware that mounting database file from a network drive is not supported and the database files may become corrupted.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.