469,077 Members | 1,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,077 developers. It's quick & easy.

Restore a database to another server

Hi, i am using sql server 2000, and i make daily backups. I want to
restore my backup to a test msde database i have. I don't know how i
did it last time.

-The database name is the same: "web" on both places
-The database is located on different hard drives and the file name
are different on both places.

I tried to do it from enterprise manager, restore database, from
device, i chose the transaction file and the database backup itself
and tried to restore, but i got an error that i don't have exclusive
access to the database.

How can i fix this?
Nov 15 '07 #1
5 7131
Seguros Catatumbo (se**************@gmail.com) writes:
Hi, i am using sql server 2000, and i make daily backups. I want to
restore my backup to a test msde database i have. I don't know how i
did it last time.

-The database name is the same: "web" on both places
-The database is located on different hard drives and the file name
are different on both places.

I tried to do it from enterprise manager, restore database, from
device, i chose the transaction file and the database backup itself
and tried to restore, but i got an error that i don't have exclusive
access to the database.
RESTORE DATABASE db FROM DISK ='filenamehere'
WITH MOVE 'logicalname1' TO 'path.mdf',
MOVE 'logicalname2' TO 'path_log.ldf',
REPLACE

logicalname1/2 are the logical names of the device file. You find these
with help of sp_helpdb on the source database, or RESTORE FILELISTONLY
on the backup file.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 15 '07 #2
RESTORE DATABASE db FROM DISK ='filenamehere'
WITH MOVE 'logicalname1' TO 'path.mdf',
MOVE 'logicalname2' TO 'path_log.ldf',
REPLACE
Hey Erland, thanks for replying. I couldn't get it to work. Here's the
command:

RESTORE DATABASE db FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE

Here's the error message:

The file 'c:\pruebadb\web_dos.mdf' cannot be overwritten. It is being
used by database 'web'.
File 'WEB_Data' cannot be restored to 'c:\pruebadb\web_dos.mdf'. Use
WITH MOVE to identify a valid location for the file.
The file 'c:\pruebadb\web_dos_log.ldf' cannot be overwritten. It is
being used by database 'web'.
File 'WEB_Log' cannot be restored to 'c:\pruebadb\web_dos_log.ldf'.
Use WITH MOVE to identify a valid location for the file.
RESTORE DATABASE is terminating abnormally.

Here's the output of sp_helpdb on the source db and destination db:

source:

WEB_Data
1 D:\DataWEB\Data
\web_Data.MDF
PRIMARY 4348096 KB Unlimited 5120 KB data only
WEB_Log
2 D:\DataWEB\Data
\web_Log.LDF
NULL 32448 KB Unlimited 10% log only
destination:

WEB_Data
1 C:\pruebadb
\web_dos.mdf
PRIMARY 2092928 KB Unlimited 5120 KB data only
WEB_Log
2 C:\pruebadb
\web_dos_log.ldf
NULL 1024 KB Unlimited 10% log only
The c:\publica\web_db_200711150500.bak was obtained from a backup made
by sql server itself on the source server itself
Nov 16 '07 #3
I made a mistake with the command. My database name is not db, it's
"web". So now i get the same error i get when i do with the GUI:

RESTORE DATABASE db FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE

Here's the error message:

Exclusive access could not be obtained because the database is in use.

Do i need to take the database offline or something?

Nov 16 '07 #4
Ok, i think i know how to fix it.

-WEB is my default database, so when i use query analizer it opens
that database. It can't restore the database if i am connected. So
instead of figuring off how to change the default database, i
connected, changed the current db to master (use master), and then i
could take web offline with enterprise manager. Now the command seems
to be working, it will take long, the database is 4GB.

RESTORE DATABASE web FROM DISK ='c:\publica\web_db_200711150500.bak'
WITH MOVE 'WEB_Data' TO 'c:\pruebadb\web_dos.mdf',
MOVE 'WEB_Log' TO 'c:\pruebadb\web_dos_log.ldf',
REPLACE
Nov 16 '07 #5
Yup, it worked, so the conclusion is that it would have worked from
the start if i just would have taken the database offline. Thanks for
your help

Nov 16 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by EggsAckley | last post: by
reply views Thread by newman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.