We are so used to taking backups and it can sometimes give us new experiences. One of the common messages I see are around taking backups on a share. If you have found this blog while searching for error message, then you may want to look at below blogs as well if you are NOT dealing with mapped drive. Let us learn about Error 3201.
This time I will explain why you are getting this error while taking backup on a mapped drive. Here is the situation:
- SQL Server Service runs under a domain account.
- You have already mapped the drive in Windows and can see that drive in Windows Explorer.
- You are not able to see the drive which is mapped. Below is the screenshot of the screen where you choose a backup file name. If you try to take a backup from SQL Server Management Studio (SSMS) you are not able to see the drive. As we can see, SSMS is only showing local drive (C and D)
- Backup command is failing with below error.
Msg 3201, Level 16, State 1, Line 1
Cannot open backup device ‘Z:\master.bak’. Operating system error 3(The system cannot find the path specified.).
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
If we try to get details about the drives visible from SQL Server by Windows “dir” command then we see below.
xp_cmdshell 'dir Z:'
The system cannot find the path specified.
(2 row(s) affected)
Above confirms that SQL is not able to see Z drive, even though it is mapped on Windows. In case you get below error
Msg 15123, Level 16, State 1, Procedure sp_configure, Line 72
The configuration option ‘xp_cmdshell’ does not exist, or it may be an advanced option.
Then you need to execute below to enable xp_cmdshell as its disabled by default due to security reasons. (Please turn off again once you done with the work)
EXEC sp_configure 'advanced', 1 RECONFIGURE WITH override GO EXEC sp_configure 'xp_cmdshell', 1 RECONFIGURE WITH override GO
We are seeing “The system cannot find the path specified.” because SQL Server instance as it is running as a service. To fix the error, we need to map the drive via SQL Server. Here are the steps.
-- Map the drive via T-SQL so that SQL can see it. EXEC xp_cmdshell 'net use Z: \\BigPinal\SharedFolder' GO
Now we can check mapped drive via T-SQL.
xp_cmdshell 'dir Z:'
You may want to add more parameters for net use. Refer Net use documentation
Once this is done, we can see that drive in SSMS as shown below
… And as expected, backup command would not fail.
Have you ever faced this situation such weird situations? What were your resolution steps? Let me know as we can learn from each other.
Reference: Pinal Dave (https://blog.sqlauthority.com)