Sql Server 2005 恢复失败
运行sql server 2005 我有数据库A。我试图从A 的备份恢复到数据库B。我想保留数据库A 并从以前的数据集创建一个新的测试数据库B。
我尝试创建 B 并从 .bak 恢复,并从 Management Studio 将数据库恢复到 B。
错误是...
标题:Microsoft SQL Server 管理
工作室
服务器恢复失败 “195448-APP2”。 (微软.SqlServer.Smo)
------------------------------------------ 其他信息:
System.Data.SqlClient.SqlError: 备份集保存一个备份 除现有“B”之外的数据库 数据库。 (微软.SqlServer.Smo)
如需帮助,请点击: http://go.microsoft .com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&LinkId=20476
------------------------------------------ 按钮:
确定
我发现了这个片段,我在犹豫是否使用它,想问一下它是否可以解决我在恢复数据库的过程中更改 mdf 和 ldf 位置的问题,或者是否可以替换数据库 A 的所有项目。
ALTER DATABASE AdventureWorks
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
RESTORE DATABASE AdventureWorks
FROM DISK = 'C\:BackupAdventureworks.bak'
WITH MOVE 'AdventureWorks_Data' TO 'C:\Data\datafile.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\Data\logfile.ldf',
REPLACE
对我来说,我会做到......
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'B' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'B_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
我什么不知道是否会影响数据库A。 我希望替换引用与 B. 相关的文件
,或者如果
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'A' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'A_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
有人可以帮助我解决错误和/或确认此修复,我将非常感激,因为这不是我正在使用的数据库。
谢谢。
Running sql server 2005 I have database A. I am trying to restore from a backup of A to database B. I want to retain the database A and create a new testing database B from a previous set of data.
I tried to create B and restore from the .bak AND restore database to B from management studio.
The error is...
TITLE: Microsoft SQL Server Management
Studio
Restore failed for Server
'195448-APP2'.
(Microsoft.SqlServer.Smo)------------------------------ ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The
backup set holds a backup of a
database other than the existing 'B'
database. (Microsoft.SqlServer.Smo)For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&LinkId=20476------------------------------ BUTTONS:
OK
I found this snippet which I am hesitant to use and want to ask if it would solve my problem of changing the location of the mdf and ldf during the process of restoring the database or does it replace database A's items altogether.
ALTER DATABASE AdventureWorks
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE
RESTORE DATABASE AdventureWorks
FROM DISK = 'C\:BackupAdventureworks.bak'
WITH MOVE 'AdventureWorks_Data' TO 'C:\Data\datafile.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\Data\logfile.ldf',
REPLACE
and for me I would make it...
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'B' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'B_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
What I don't know is if it will affect database A at all. I am hoping the replace refers files associated with B.
or if it should be
RESTORE DATABASE B
FROM DISK = 'C:\backupofA.bak'
WITH
MOVE 'A' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B.mdf',
MOVE 'A_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\B_log.ldf',
REPLACE
If anyone could help me with the error and/or confirm this fix I would be very grateful as it is not my database I'm playing with.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您只需使用复制数据库向导即可。
如果您想像专业人士一样使用 T-SQL,RESTORE .. MOVE ... REPLACE 将执行您所期望的操作:将两个文件移动到您想要的位置,并用备份中的内容替换数据库 B。 A 将不受影响。
You could simply use the Copy Database Wizard.
If you wanna do it like pros and use T-SQL the RESTORE .. MOVE ... REPLACE will do what you expected: move the two files at the locations you intend and replace database B with content from the backup. A will be unaffected.
如果我是您,我会使用该向导:在 Sql Server Management Studio 中右键单击“数据库”并选择“恢复数据库...”。 此对话框/向导将完全按照您的要求进行操作 - 只需选择要从中恢复的源 .bak 文件/数据库,输入要恢复到的数据库的名称,然后单击“确定”。
一些注意事项 - 如果您输入尚不存在的数据库名称(听起来这就是您想要做的),它将为您创建该数据库。 如果您输入现有数据库的名称,它将尝试恢复到该数据库。 如果您尝试从由不同数据库组成的备份恢复到现有数据库,它将失败,但是您可以通过转到“选项”并选中“覆盖现有数据库”复选框来强制 Sql Server 覆盖现有数据库。
此外,如果您要恢复现有数据库的备份以创建该数据库的第二个新副本,您可能会发现向导失败,因为它尝试使用与源当前使用的数据库文件路径相同的数据库文件路径来创建数据库数据库。 要解决此问题,您需要单击“选项”并将所有“还原为”文件路径更改为尚不存在的文件。
您还可以让此向导生成 SQL 脚本,而不是实际执行实际恢复(单击顶部的“脚本”按钮),如果您想学习如何在原始 SQL 中执行此类操作,这会很方便。
I would use the wizard if I were you: In Sql Server Management Studio right click on "Databases" and select "Restore Database...". This dialog / wizard will do exactly what you are asking - simply select the source .bak file(s) / Database that you want to restore from, enter the name of the database you want to restore to and hit "Ok".
Some notes - if you enter the name of a database that doesnt yet exist (it sounds like this is what you want to do), it will create that database for you. If you enter the name of an existing database it will attempt to restore to that database. If you attempt to restore to an existing database from a backup made of a different database it will fail, however you can force the Sql Server to overwrite the existing database by going to "Options" and checking the "Overwrite the existing database" checkbox.
Also, if you are restoring a backup of an existing database to create a new second copy of that database you may find that the wizard fails as its attempting to create a database using the same database file paths as the ones currently in use by the source database. To fix this you need to click on "Options" and change all of the "Restore As" file paths to files that dont yet exist.
You can also get this wizard to generate an SQL script instead of actually performing the actual restore (click on the "script" button at the top), which is handy if you want learn how to do this sort of thing in raw SQL instead.
可以将数据库从 sql server 7、sql server 2000 恢复到 sql server 2005。
它可以通过使用恢复和替换命令来实现。
使用此脚本可以轻松地在 sql server 中进行备份,无需任何外部工具。
查看恢复示例< /a>.
It is possible to restore a database from sql server 7, sql server 2000 to sql server 2005.
It can be achieved by using restore and with replace command
It is easy to take a backup in sql server using this script without any external tools.
Check out Restore with Example.
首先删除数据库 b。 然后进行恢复。
drop database b first. then do the restore.