Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 561 Guide

· 8 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Fix SQL Server Error 561 by granting the SQL service account 'Full Control' permissions to the database file directory and its parent folders, ensuring the account has permission to modify, create, and delete files. This error usually occurs when a database file location is moved, the service account loses access, or a permissions issue prevents SQL Server from reading or writing to the data or log files on the storage volume.

What You'll Need

  • Administrator access to the Windows Server or workstation where SQL Server is installed.
  • Access to the server's File Explorer or command prompt.
  • The SQL Server service account name (often found in SQL Server Configuration Manager).
  • Access to the Database Properties dialog in SQL Server Management Studio (SSMS) to verify file locations.

Step-by-Step

  1. Identify the Service Account: Open SQL Server Configuration Manager. Expand the SQL Server Network Configuration node, then SQL Server Services. Right-click the SQL Server instance you are troubleshooting (e.g., SQL Server (MSSQLSERVER)) and select Properties. Go to the Service tab. In the Log on as section, note the account name. This is the account that must have access to the files.
  2. Locate the Database Files: Open SQL Server Management Studio (SSMS) and connect to the instance. In the Object Explorer, right-click the database that is generating the error and select Properties. Go to the Files page. Note the path listed in the Path column for the primary data file (e.g., C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\MyDatabase.mdf) and the transaction log (e.g., C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\MyDatabase_log.ldf). You need to check the folder path, not just the file name.
  3. Verify Folder Existence: Open File Explorer and navigate to the directory listed in the previous step. Attempt to open it. If the folder does not exist, SQL Server cannot create the database files. Create the folder if necessary. Ensure the folder is not empty; if it is, SQL Server cannot create a new file in it.
  4. Grant Permissions to the Service Account: Right-click the folder containing the database files and select Properties. Go to the Security tab. Click Edit, then Add. Type the name of the SQL Server service account (e.g., NT SERVICE\MSSQLSERVER or a domain account like CONTOSO\SQLService) and click Check Names. Click OK to add the user to the list. Select the new user in the list and check the Allow checkboxes for Full Control. This grants the account permission to read, write, and modify files in this folder.
  5. Grant Permissions to Parent Folders: Right-click the parent folder of the database files (e.g., C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA if the database is inside the DATA folder) and select Properties. Repeat the permission granting process from step 4. This is a critical step; if the service account lacks permissions on the parent directory, it cannot create subdirectories or new files, leading to Error 561.
  6. Apply Permissions to All Subfolders: If your database files are stored deep within a directory structure, you must ensure the service account has permissions all the way up to the root of the drive or the shared folder. You can automate this by checking the Replace child object permissions with inheritable permissions from this object checkbox when applying permissions to the parent folder.
  7. Test the Connection: Return to SQL Server Management Studio and attempt to execute a simple query against the database. If the error persists, the issue may be a deeper permission problem or a network drive issue.
  8. Check for Read-Only Status: Ensure the drive containing the database files is not marked as read-only. In File Explorer, right-click the drive letter (e.g., E:) and select Properties. On the General tab, ensure the Read-only checkbox is unchecked.
  9. Verify File Ownership: If you moved database files manually, the files may be owned by a different user. In File Explorer, right-click the database file (.mdf or .ldf), select Properties, go to the Security tab, and click Advanced. Under the Owner tab, click Edit. Select the SQL Server service account and check the box to Replace owner on subcontainers and objects. Click Apply and confirm.
  10. Restart the SQL Server Service: After applying all permission changes, the SQL Server service must be restarted for the changes to take effect. In SQL Server Configuration Manager, right-click the SQL Server service and select Restart. Attempt to access the database again.

Common Mistakes

  • Granting Permissions to the Wrong Account: It is common to give permissions to the Windows user currently logged into the SSMS window. However, SQL Server runs as a specific Windows Service account. If this account is not granted permissions, the error will persist even if the user currently logged in can access the files.
  • Forgetting the Parent Folder: Many users grant permissions to the exact folder where the .mdf and .ldf files are located but forget the parent folder. SQL Server requires write access to the parent folder to create new files or manage temporary files, so this oversight is a frequent cause of this error.
  • Ignoring the 'Modify' vs 'Full Control' Nuance: While 'Full Control' is the easiest solution, it is not always the most secure. In some environments, you may only need the Modify permission, which allows for reading, writing, changing, and deleting files but not changing permissions themselves. However, 'Full Control' is the standard fix for Error 561.
  • Not Restarting the Service: Windows permissions are cached. Simply granting permissions through the GUI does not always immediately update the security token of a running Windows service. Restarting the SQL Server service is an essential final step.

Tips

  • Use UNC Paths for Network Shares: If your database files are on a network share, ensure you are using a Universal Naming Convention (UNC) path (e.g., \\ServerName\ShareName\Folder\File.mdf) rather than a mapped drive letter. Sometimes mapped drives can be disconnected or have their permissions changed independently of the server's access.
  • Check the Error Log: If the fix does not work immediately, check the SQL Server Error Log. It may provide more specific details about which file or folder is being denied access, which can save time in troubleshooting.
  • Use the 'icacls' Command: For a more precise and programmatic fix, you can use the Windows command line. Run icacls "C:\Path\To\DatabaseFiles" /grant "NT SERVICE\MSSQLSERVER:(OI)(CI)F" /T. This command grants the SQL Server service account Full Control on this folder and all its subfolders.
  • Verify Drive Letter Mappings: If the database was originally set up on a mapped drive (e.g., Z:) and that drive is no longer mapped, the database properties will still point to Z:. SQL Server will fail to find the file. You must update the database file paths in SSMS to point to the actual folder location.

Troubleshooting

If you have followed the steps above and still receive Error 561, consider the following advanced checks:

  • Check for Antivirus or Encryption Software: Some third-party antivirus solutions or disk encryption tools (like BitLocker) can interfere with file access by the SQL Server service account. Temporarily disabling these tools can help determine if they are the root cause. Ensure any antivirus product you use has an exception or whitelist for the SQL Server data directory.
  • Verify File System Format: Ensure the drive containing the database files is formatted with NTFS. FAT32 or exFAT file systems do not support file ownership or granular permissions as securely as NTFS. SQL Server generally requires NTFS for proper permission management.
  • Check for 'System' Account Conflicts: If the database files are located on a system drive (C:), they may be owned by the SYSTEM account. While the SQL Server service account usually has permissions to access system files, if the file ownership was manually changed to a standard user, the SQL Server service may be denied access. Resetting the ownership to SYSTEM or granting permissions to the SQL Server service account can resolve this.
  • Review the SQL Server Agent Service: If the error occurs when a job is running, check the SQL Server Agent service account. The Agent service often runs as a different account than the main SQL Server engine. Ensure this agent account also has permissions to the database files.
  • Check for Disk Space: While Error 561 is primarily a permissions error, a lack of disk space can sometimes manifest similarly. Ensure that the drive has sufficient free space to create or expand the database files.

Frequently Asked Questions

What does SQL Server Error 561 mean exactly?

Error 561 is a file system error that indicates SQL Server failed to access or perform an operation on a database file. It is not a database-level error but rather an operating system error caused by a lack of access permissions or a file system issue.

Can I move the database files to a different drive to fix this?

You can move the files, but you must update the database's file paths in SSMS afterward. Simply moving the files without updating the internal SQL Server references will cause the same error. Moving files can sometimes help if the original drive has no space or permissions issues.

Is it safe to give the SQL Server service account 'Full Control'?

It is considered acceptable practice to grant Full Control on the specific database data folder and its parent folder for the SQL Server service account. This is necessary for the database engine to function. Ensure this folder is not accessible by other untrusted users to maintain security.

Why does this error happen after a Windows update?

Windows updates can sometimes reset local user permissions or change the security context of services. After a major update, it is good practice to verify that the SQL Server service account still has the necessary permissions on its data files.

Does this error prevent me from restoring a database backup?

If you try to restore a database backup and receive Error 561, it means SQL Server cannot write the restored files to the specified location. You must first ensure the destination folder has the correct permissions before attempting the restore.

Can I run SQL Server as a local user instead of a service account?

SQL Server can be configured to run as a specific local Windows user account, not just the built-in service accounts. If you are using a custom local user account, ensure that account is explicitly granted permissions to the database files.