Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 restoring the db, why do I have to make changes?

Author  Topic 

chedderslam
Posting Yak Master

223 Posts

Posted - 2008-07-15 : 15:22:08
I was attempting to restore a .bak on my local box for development work. I went through the wizard in sql server management studio, and got this error:

------------------------------
ADDITIONAL INFORMATION:

System.Data.SqlClient.SqlError: File 'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db.mdf' is claimed by 'si_production_db_pri_2'(4) and 'si_production_db_Data'(1). The WITH MOVE clause can be used to relocate one or more files. (Microsoft.SqlServer.Smo)
------------------------------
I tried scripting it to a query window, and got this code generated:
------------------------------
RESTORE DATABASE [si_training_db] FROM DISK = N'C:\Documents and Settings\k5imimps\Desktop\mydocumentsbackup\si_deploy.bak' WITH FILE = 1, MOVE N'si_production_db_Data' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db.mdf', MOVE N'si_production_db_pri_2' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db.mdf', MOVE N'si_production_db_data1' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db.mdf', MOVE N'si_production_db_Log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db_1.ldf', NOUNLOAD, STATS = 10
GO
------------------------------

The move command is set up to restore all the physical files to the same file, "c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db.mdf".

I got the db to restore by adding sequential numbers to the script, so it turned out to work by doing this:
------------------------------
RESTORE DATABASE [si_training_db] FROM DISK = N'C:\Documents and Settings\k5imimps\Desktop\mydocumentsbackup\si_deploy.bak' WITH FILE = 1, MOVE N'si_production_db_Data' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db1.mdf', MOVE N'si_production_db_pri_2' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db2.mdf', MOVE N'si_production_db_data1' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db3.mdf', MOVE N'si_production_db_Log' TO N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\si_training_db_1.ldf', NOUNLOAD, STATS = 10
GO
------------------------------

My first question is, am I creating any problems with the changes to the script that I made?
Secondly, Why would management studio generate a script that is broken?

Thanks.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-07-15 : 15:32:43
Why are you restoring to C drive?
Go to Top of Page

chedderslam
Posting Yak Master

223 Posts

Posted - 2008-07-15 : 15:37:54
This is my local box for development purposes.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-07-15 : 23:02:27
Because file path stored in sysfiles table is different from file path on target machine.
Go to Top of Page
   

- Advertisement -