473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Restore Database Fails

I'm trying to use ADO to restore a SQL 7 database using a backup file. The
database already exists on the target computer, and is named the same as on
the source computer, and the MDF and LDF files are named the same as well.

I am running the below in a stored procedure:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE 'DB1' TO 'c:\mssql7\data\DB1.mdf',
MOVE 'DB1_log' TO 'c:\mssql7\data\DB1_log.ldf'

And I get an error message "File 'DB1' is not a database file for database
'DB1' ".

I also tried it without the LDF file in the expression. Same results.

Thanks.

Jun 4 '07 #1
5 4425
Neil (no****@nospam.net) writes:
I'm trying to use ADO to restore a SQL 7 database using a backup file.
The database already exists on the target computer, and is named the
same as on the source computer, and the MDF and LDF files are named the
same as well.

I am running the below in a stored procedure:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE 'DB1' TO 'c:\mssql7\data\DB1.mdf',
MOVE 'DB1_log' TO 'c:\mssql7\data\DB1_log.ldf'

And I get an error message "File 'DB1' is not a database file for database
'DB1' ".
Add ", REPLACE" to your command.
--
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
Jun 4 '07 #2
OK, replaced the original command with:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE DB1 TO 'c:\mssql7\data\DB1.mdf',
MOVE DB1_log' TO 'c:\mssql7\data\DB1_log.ldf',
REPLACE

Got the same error message.

"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
Neil (no****@nospam.net) writes:
>I'm trying to use ADO to restore a SQL 7 database using a backup file.
The database already exists on the target computer, and is named the
same as on the source computer, and the MDF and LDF files are named the
same as well.

I am running the below in a stored procedure:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE 'DB1' TO 'c:\mssql7\data\DB1.mdf',
MOVE 'DB1_log' TO 'c:\mssql7\data\DB1_log.ldf'

And I get an error message "File 'DB1' is not a database file for
database
'DB1' ".

Add ", REPLACE" to your command.
--
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

Jun 4 '07 #3
As a followup to my previous message, I also tried the modified command
directly from Query Analyzer, and got the same message. I then tried to
restore the backup file from Enterprise Manager, and it worked fine. But
couldn't get the SQL to work.

However, I still need to get it to work, as I have an associate who needs to
restore the same backup set, but he doesn't have QA or EM. He's running the
SQL in a stored procedure using ADO.

Thanks,

Neil
"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
Neil (no****@nospam.net) writes:
>I'm trying to use ADO to restore a SQL 7 database using a backup file.
The database already exists on the target computer, and is named the
same as on the source computer, and the MDF and LDF files are named the
same as well.

I am running the below in a stored procedure:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE 'DB1' TO 'c:\mssql7\data\DB1.mdf',
MOVE 'DB1_log' TO 'c:\mssql7\data\DB1_log.ldf'

And I get an error message "File 'DB1' is not a database file for
database
'DB1' ".

Add ", REPLACE" to your command.
--
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

Jun 5 '07 #4
OK, I got it to work. Seems I was using MOVE to move the MDF and LDF to
those locations; but the MDF and LDF for the database that was being
overwritten were already at those locations. So I removed the MOVE commands,
and it worked fine. The final version was:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH RESTORE

Thanks!

Neil
"Erland Sommarskog" <es****@sommarskog.sewrote in message
news:Xn**********************@127.0.0.1...
Neil (no****@nospam.net) writes:
>I'm trying to use ADO to restore a SQL 7 database using a backup file.
The database already exists on the target computer, and is named the
same as on the source computer, and the MDF and LDF files are named the
same as well.

I am running the below in a stored procedure:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE 'DB1' TO 'c:\mssql7\data\DB1.mdf',
MOVE 'DB1_log' TO 'c:\mssql7\data\DB1_log.ldf'

And I get an error message "File 'DB1' is not a database file for
database
'DB1' ".

Add ", REPLACE" to your command.
--
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

Jun 5 '07 #5
Neil (no****@nospam.net) writes:
OK, replaced the original command with:

RESTORE DATABASE DB1
FROM DISK = 'c:\mssql7\backup\DB1.bak'
WITH MOVE DB1 TO 'c:\mssql7\data\DB1.mdf',
MOVE DB1_log' TO 'c:\mssql7\data\DB1_log.ldf',
REPLACE

Got the same error message.

The the problem is that the logical names of the files are not DB1 and
DB1_log. You can retrieve these names with RESTORE FILELISTONLY.
--
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
Jun 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: FoxRunner | last post by:
Hi folks, I got a script which restores a database. It works fine if it is running in my Query Analyzer. It fails when I put this script in an automated schedule using the SQL agent. This...
2
by: jbmccluskey | last post by:
I'm a newbie so please be gentle. In attempting to run a restore I get the following error message: "Exclusive access could not be obtained because the database is in use." However, it doesn't...
2
by: DMAC | last post by:
The following failed in EM (or whatever it is called now management studio I think) and I scripted it out and ran it in a query window to get more info. This works fine in SQL 2000 but not in 2005....
4
by: Andy J | last post by:
Hi Everyone NEW USER Q. I am trying to restore a database backup image to another machine. Both machines are installed with same DB2 7.2 installation package. Version: 7, Release: 2,...
1
by: ad | last post by:
I want to backup and restore a database in asp.net. The backup process is successful and fail when restore with message: User does not have permission to RESTORE database 'Health'. RESTORE...
2
by: san | last post by:
Hello, i am in great trouble. I want to revert back to original state of database before i performed restore database on my sql server 2K Database. Accidently i didn't take backup of my Database...
1
by: Utahduck | last post by:
I've been having some issues so forgive me if this double-posts. Because I have some large but static Filegroups within a database I prefer to backup my filegroups instead of everything at once. ...
1
by: GitarJake | last post by:
Hello, I am getting the rather odd error below; hope you can help. RESTORE DATABASE is terminating abnormally. File 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\trial_44testingc'...
3
by: Bill E. | last post by:
I'm trying to restore a database backed up a production machine onto my development machine. I don't want to restore the transaction logs (there are two) because they are far too large and are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.