Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article provides a workaround for the 3156 error, which occurs when you try to restore a database that has a memory-optimized filegroup in SQL Server.
Applies to: SQL Server
Symptoms
When trying to restore a database that has a memory-optimized filegroup in SQL Server, you receive the following error message:
Msg 3156, Level 16, State 6, Line 1
File '<Database File>' cannot be restored to '<Driver>:\<Folder Path>\<Database Folder>'. Use WITH MOVE to identify a valid location for the file.
Cause
During the process of a database restoration, SQL Server Database Engine will create a folder for a memory-optimized filegroup. This issue occurs if there's already a folder with the same name in the same folder path, and the folder is used by SQL Server or other processes.
Workaround
Use a different folder name or a different folder path when restoring a database.
Script example
Script example of creating a database with a filegroup
USE [master]; GO CREATE DATABASE Contoso ON PRIMARY ( NAME = 'Contoso_Primary', FILENAME= 'C:\SQLserver\Contoso\Contoso_data.mdf', SIZE=4MB, MAXSIZE=10MB, FILEGROWTH=1MB), FILEGROUP Contoso_FG1 ( NAME = 'Contoso_FG1', FILENAME = 'C:\SQLserver\Contoso\Contoso_FG1.ndf', SIZE = 1MB, MAXSIZE=10MB, FILEGROWTH=1MB) ALTER DATABASE Contoso ADD FILEGROUP [Contoso_FG1] CONTAINS MEMORY_OPTIMIZED_DATA GOScript example of a database restoration
USE [master] GO RESTORE DATABASE [Contoso] FROM DISK = N'C:\backup\compress\Contoso\Contoso.bak' WITH FILE = 1, MOVE N'Contoso_data' TO N'C:\SQLserver\Contoso\Contoso_data.mdf', MOVE N'Contoso_log' TO N'C:\SQLServer\Contoso\Contoso_log.ldf', MOVE N'<Database File>' TO N'<Driver>:\<Folder Path>\<Database Folder>', Replace, NOUNLOAD, STATS = 5 GONote
If the
<Database Folder>is not used, theReplacekeyword in the script will ensure that the process of restoration is completed without error.