posted 5/31/2012 by TomLannen - Views: [3759]
The other day I was at a client site, and I was trying to set up my development environment to begin working on some SSIS packages. I was on the next to last restore of 12 separate DB (all told, over 500GB), when the restore failed. Up to this point I hadn?t had any issues at all. Then this sucker popped up:
TITLE: Microsoft SQL Server Management Studio ------------------------------ Restore failed for Server. (Microsoft.SqlServer.SmoExtended) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText]&EvtID=Restore+Server&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: System.Data.SqlClient.SqlError: File 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\SomeNewDB.mdf' is claimed by 'SomeNewDB_UserData'(3) and 'SomeNewDB_Primary'(1). The WITH MOVE clause can be used to relocate one or more files. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&LinkId=20476 ------------------------------ BUTTONS: OK
The link provided in the first part of the message led absolutely nowhere, and the second one wasn?t much help either. Strangely enough I read the error message a few times, and for once I was able to determine what the problem was. Here was the key to the error message: File 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\ SomeNewDB.mdf' is claimed by 'SomeNewDB_UserData'(3) and 'SomeNewDB_Primary'(1).
So what I did was script out the restore and discovered that I was trying to use the .mdf file twice.
RESTORE DATABASE [SomeNewDB]
FROM DISK = N'C:\SQLBackup\SomeNewDB.bak'
WITH FILE = 1,
MOVE N'SomeNewDB_Primary'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\SomeNewDB.mdf',
MOVE N'SomeNewDB_UserData'
MOVE N'SomeNewDB_Log'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\SomeNewDB_1.ldf',
NOUNLOAD, REPLACE, STATS = 10
GO
So I changed the second file to .ndf and ran the script and it seemed to work.
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\SomeNewDB.ndf',
So if you ever run into that problem make sure your not trying to reference the .mdf file twice inside your restore statement.