Error 32 When Restoring Database

I'm attempting to restore a SQL Server 2008 R2 backup into a SQL Server 2014 database WITH MOVE but am encountering the following error:

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 'E:\Intuitive8.7Data\iERP87_Data.mdf'.

Following is the code I'm using attempting to accomplish this:

USE Master
GO

ALTER DATABASE iERP87 SET OFFLINE WITH ROLLBACK IMMEDIATE;

RESTORE DATABASE [iERP87]
FROM DISK = N'E:\Temp\iERP81_2008.bak'
WITH
MOVE N'Production70_Data' TO N'E:\Intuitive8.7Data\iERP87_Data.mdf',
MOVE N'Production70_Log' TO N'E:\Intuitive8.7Log\iERP87_Log.ldf',
NOUNLOAD, REPLACE, STATS = 10

ALTER DATABASE iERP87 SET ONLINE WITH ROLLBACK IMMEDIATE;

As a result of searching on-line for help I have user "Process Explorer" to look for processes using the mdf file without finding any and have rebooted the server to ensure there are no other open connections.

I've run out of ideas on this one.  Any help would be most appreciated.

May 28th, 2015 4:18pm

So  you already have the database iERP87 on SQL 2014 instance, right?? if not - then why are you  setting the database to offline

Do you already have the database files(mdf,ldf) in that location, right?? are these sql 2008R2 files or 2014 files

and you want to overwrite this database with backup, right??

If so, USE Replace at the end of the script and you probably do not need MOVE command  or else MOVE the database files to different location or change the file name

Again first confirm on these three questions 

RESTORE DATABASE [iERP87] 
FROM DISK = N'E:\Temp\iERP81_2008.bak' With Replace

Free Windows Admin Tool Kit Click here and download it now
May 28th, 2015 4:53pm

Rather than setting the database offline (and permit AV and other evil forces to set their teeth into it), set it to SINGLE_USER (and MULTI_USER when you are done).

May 28th, 2015 5:50pm

Hi,

In Addition to Stan's answer,

As the error describes that your database files are in use by an existing database that is online. If you want to overwrite this, the only way is to use WITH  REPLACE option while restoring.

Don't get confused with the existing connections only being the ones from the users or clients. In this case it is SQL server database holding a connection to its respective files(.mdf & .ldf files) as it is online and cant be overwritten unless specified.

Hope this helps

Thanks



Free Windows Admin Tool Kit Click here and download it now
May 28th, 2015 5:58pm

1)verify and see file list 

RESTORE VERIFYONLY
FROM DISK = 'E:\Temp\iERP81_2008.bak';

RESTORE filelistONLY
FROM DISK = 'E:\Temp\iERP81_2008.bak';

2) make database single user mode

3) restore

4) make database multiuser

    no need make database offline.

May 28th, 2015 9:22pm

When DB is already on the instance where we perform restore we cannot use the same file names with MOVE command. Please change the file names / use WITH REPLACE option. If we need same DB name either rename old DB to _OLD or go for replace.
Free Windows Admin Tool Kit Click here and download it now
May 28th, 2015 9:49pm

Hi,

In Addition to Stan's answer,

As the error describes that your database files are in use by an existing database that is online. If you want to overwrite this, the only way is to use WITH  REPLACE option while restoring.

Don't get confused with the existing connections only being the ones from the users or clients. In this case it is SQL server database holding a connection to its respective files(.mdf & .ldf files) as it is online and cant be overwritten unless specified.

Hope this helps

Thanks



May 28th, 2015 9:52pm

Hi,

In Addition to Stan's answer,

As the error describes that your database files are in use by an existing database that is online. If you want to overwrite this, the only way is to use WITH  REPLACE option while restoring.

Don't get confused with the existing connections only being the ones from the users or clients. In this case it is SQL server database holding a connection to its respective files(.mdf & .ldf files) as it is online and cant be overwritten unless specified.

Hope this helps

Thanks



Free Windows Admin Tool Kit Click here and download it now
May 28th, 2015 9:52pm

The database iERP87 already exists.

The existing iERP87 database's mdf and ldf files are in the locations specified.

Yes, I am attempting to overwrite iERP87 with a backup from the older iERP81 database which is currently in production on another server. 

The purpose of this exercise is to upgrade to a newer version of the database application on a new server running a newer version of SQL Server.  I have done this many times at different locations, but this issue is a first for me.

May 29th, 2015 9:37am

Point taken, I made the change, but it still did not resolve my issue.
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 9:38am

REPLACE was one of the WITH parameters; it was listed after the MOVE parameters.  I relocated it to the beginning of the WITH string but it did not resolve the issue.
May 29th, 2015 9:40am

Running the RESTORE VERIFYONLY informs me the physical files don't exist (which I know because they are on a different server) but that the backup file is good.

Running the RESTORE FILELISTONLY confirms that I have the correct logical file names associated with the old database from which I'm restoring to this new one.

Thus no new insight here or progress in resolving my problem.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 9:44am

The old database was named iERP81 and the new one is iERP87, thus they have different database names.  Their physical file names are also different hence my use of the MOVE parameters.
May 29th, 2015 9:46am

So if you do

sp_helpdb iERP87

do you see the files listed in the script?

I'm starting to suspect that there is a second instance on the server, and the files you are trying to use are attached to that instance.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 6:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics