FIX: Unable to restore a database by using REPLACE option if the filepath contains redundant path separators in SQL Server 2017

Applies to: SQL Server 2017 DeveloperSQL Server 2017 EnterpriseSQL Server 2017 Enterprise Core

Symptoms


Assume that you are trying to restore a database by using REPLACE option in SQL Server 2017. If the filepath contains redundant path separators in CREATE DATABASE, you may receive error messages that resemble the following:

Msg 3634, Level 16, State 1, Line LineNumber

The operating system returned the error '32(The process cannot access the file because it is being used by another process.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'FilePath\FileName.mdf'.

Msg 3156, Level 16, State 8, Line LineNumber

File 'FileName' cannot be restored to 'FilePath\FileName.mdf'. Use WITH MOVE to identify a valid location for the file.

Msg 3634, Level 16, State 1, Line LineNumber

The operating system returned the error '32(The process cannot access the file because it is being used by another process.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'FilePath\FileName.ldf'.

Msg 3156, Level 16, State 8, Line LineNumber

File 'FileName' cannot be restored to 'FilePath\FileName.ldf'. Use WITH MOVE to identify a valid location for the file.

Msg 3119, Level 16, State 1, Line LineNumber

Problems were identified while planning for the RESTORE statement. Previous messages provide details.

Msg 3013, Level 16, State 1, Line LineNumber

RESTORE DATABASE is terminating abnormally.

Workaround


You get this error when you are trying to do restore with REPLACE option. As a workaround, you can delete the existing database and do a restore.

Resolution


This issue is fixed in the following cumulative update for SQL Server:

       Cumulative Update 4 for SQL Server 2017

More information


About the path, it's not the path to the backup location, it’s the path of the file in the backup header which can be viewed with restore headers only. For more information, see RESTORE Statements - HEADERONLY (Transact-SQL). For example:

RESTORE HEADERONLYFROM DISK = N'FilePath\FileName.bak'WITH NOUNLOAD;GO

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

References


Learn about the terminology that Microsoft uses to describe software updates.