Click here to Skip to main content
13,400,969 members (39,864 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 9 Jan 2014

Solution: The WITH MOVE Clause Can Be Used to Relocate One or More Files

, 9 Jan 2014
Rate this:
Please Sign up or sign in to vote.
The WITH MOVE clause can be used to relocate one or more files

Today, while working with SQL Server, I was trying to restore a DB from .bak file and got a strange error while restoring using the normal procedure. I was working on SQL Server 2008 R2 and the backup was from an old version making me think the problem may be because of incorrect SQL versions. The error read as below:

Microsoft SQL Server Management Studio
Restore failed for Server ‘MYSQLSERVER’. (Microsoft.SqlServer.SmoExtended)
For help, click:



File ‘C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDatabase.mdf’ 
is claimed by ‘MyDatabase_log’(2) and ‘MyDatabase’(1). 
The WITH MOVE clause can be used to relocate one or more files. (Microsoft.SqlServer.Smo)

For help, click

As usual, the links provided by SQL Server were of least use. After reading the error closely a few times, I understood the error is not related to SQL Server version but is related to the files being used by the restoration. It was found that the .mdf file of the database is being used twice by the restoration process and hence tried to restore the database using a script. Below is the solution to restore the database using a script.

FROM DISK = N'E:\MyDatabase.bak'
MOVE N'MyDatabase'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\MyDatabase.mdf',
MOVE N'MyDatabase_Log'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\MyDatabase.ldf',

Using the script and changing proper values for your database, you will be able to restore the database with ease. Hope you like this post! :)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nitesh Luharuka
Team Leader Director @ Rebin Infotech
India India
An Independent IT Professional and Consultant on MS Technologies like .Net | MVC | Silverlight | Sharepoint | MS Project Server along with open source CMS Systems like DotNetNuke etc.

I am an enthusiastic technocrat who love to debug problems and solve them. I love writing articles on my website in my spare time. Please visit my Website for more details and subscribe to get technology related tips/tricks.

You may also be interested in...


Comments and Discussions

PraiseSaved me a headache -Thanks! Pin
SwankIBS15-Mar-16 5:35
memberSwankIBS15-Mar-16 5:35 
GeneralRe: Saved me a headache -Thanks! Pin
Nitesh Luharuka21-Mar-16 3:37
professionalNitesh Luharuka21-Mar-16 3:37 
AnswerWorked for me! Pin
Member 1178409522-Jun-15 9:07
memberMember 1178409522-Jun-15 9:07 
GeneralRe: Worked for me! Pin
Nitesh Luharuka22-Jun-15 9:15
memberNitesh Luharuka22-Jun-15 9:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180218.2 | Last Updated 9 Jan 2014
Article Copyright 2014 by Nitesh Luharuka
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid