System.Data.SqlClient.SqlError: The operating system returned the error ’32(The process cannot access the file because it is being used by another process.)’

 

ERROR MESSAGE:

System.Data.SqlClient.SqlError: 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 ‘C:\test\mydb.mdf’. (Microsoft.SqlServer.Smo)

EXPLANATION:

You may receive this error when you try to restore a backup file to SQL Server.

You cannot restore the backup file because the same files you want to restore are already open and in use.

For example, you want to restore your backup file from SQL Server Management Studio.

The Restore screen has a list of “Restore the database files as:” on the “Options” tab. This list contains the database files in your backup.

This error means that the files with the same names are already being used by SQL Server. That is, you are trying to overwrite the file that was previously created and belongs to a database that is used by SQL Server.

 

SOLUTION:

You can solve the problem by modifying the file path or file name information in the “Restore the database files as:” list on the “Options” tab.

Ekrem Önsoy
Author: Ekrem Önsoy

The original article was written in Turkish by Ekrem Önsoy and translated to English by dbtut with the consent of the author. The copyright of the article belongs to the author. The author shall not be liable in any way for any defect caused by translation.

Leave a Reply

Your email address will not be published. Required fields are marked *