SQL SERVER – Backup on mapped drive failing with error – Error 3201, Level 16, State 1

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.

SQL SERVER – Error: Fix: Msg 5133, Level 16, State 1, Line 2 Directory lookup for the file failed with the operating system error 2(The system cannot find the file specified.) – Part 2

This time I will explain why you are getting this error while taking backup on a mapped drive. Here is the situation:

  1. SQL Server Service runs under a domain account.
  2. You have already mapped the drive in Windows and can see that drive in Windows Explorer.
    SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-01
  3. 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)
    SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-02
  1. 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.

SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-03

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:'

Output
———————————————–
The system cannot find the path specified.
NULL
(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

 

SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-04

Now we can check mapped drive via T-SQL.

xp_cmdshell 'dir Z:'

SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-05

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

SQL SERVER - Backup on mapped drive failing with error - Error 3201, Level 16, State 1 bkp-map-drive-06

… 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)

SQL Error Messages, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Marking Filegroup as ReadOnly with SQL Server
Next Post
SQL SERVER – Adding a Master Data Services to your Enterprise – Notes from the Field #072

Related Posts

Leave a Reply