SQL Server 2005 restore error message
This is definitely a note to self, as I'm sure to have this happen again. I received the following error message this morning when attempting to restore a database
Msg 3219, Level 16, State 3, Line 2The file or filegroup "MyDB_log" cannot be selected for this operation.
using script similar to the followingRESTORE database [MyDB]
FILE = N'MyDB' ,
FILE = N'MyDB_log' ,
FROM disk = N'C:\MyDB_backup.bak'
WITH FILE = 1,
MOVE N'MyDB' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\MyDB.mdf',
MOVE N'MyDB_log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\MyDB.ldf',
NOUNLOAD, REPLACE, STATS = 10
GOTo fix this, I simply removed the lines starting with FILE and ran it again. Success! So the final, working script wasRESTORE database [MyDB]
FROM disk = N'C:\MyDB_backup.bak'
WITH FILE = 1,
MOVE N'MyDB' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\MyDB.mdf',
MOVE N'MyDB_log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\MyDB.ldf',
NOUNLOAD, REPLACE, STATS = 10
GO