执行创建备份的SP并使用新名称恢复时出现以下错误

时间:2011-08-22 06:55:44

标签: sql-server

任何人都可以帮我找到下面SP中的错误。

USE [master]
GO
/****** Object:  StoredProcedure [dbo].[CopyDB]    Script Date: 08/22/2011 12:20:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[CopyDB](@DBName varchar(100),@Newname varchar(100))
as
DECLARE @FileName AS nvarchar(4000)
set @FileName = 'D:\'+@DBName+'.bak'
/*Backup the database*/
BACKUP DATABASE @DBName
TO DISK = @FileName
WITH CHECKSUM, INIT;
/*to restore it with new name*/
declare @st1 varchar(100)
declare @st2 varchar(100)
set @st1 = 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\'+@Newname+'.mdf';
set @st2 = 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\'+@Newname+'_log.LDF';
declare @DBName_Log varchar(100)
set  @DBName_Log = @DBName+'_Log'
RESTORE database @Newname
FROM DISK = @FileName
with 
MOVE @DBName TO @st1,
MOVE @DBName_Log TO @st2,
CHECKSUM;

我收到以下错误

Msg 5133, Level 16, State 1, Procedure CopyDB, Line 34
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\back.mdf" failed with the operating system error 3(The system cannot find the path specified.).
Msg 3156, Level 16, State 3, Procedure CopyDB, Line 34
File 'pubs' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\back.mdf'. Use WITH MOVE to identify a valid location for the file.
Msg 5133, Level 16, State 1, Procedure CopyDB, Line 34
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\back_log.LDF" failed with the operating system error 3(The system cannot find the path specified.).
Msg 3156, Level 16, State 3, Procedure CopyDB, Line 34
File 'pubs_log' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\back_log.LDF'. Use WITH MOVE to identify a valid location for the file.
Msg 3119, Level 16, State 1, Procedure CopyDB, Line 34
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
Msg 3013, Level 16, State 1, Procedure CopyDB, Line 34
RESTORE DATABASE is terminating abnormally.

1 个答案:

答案 0 :(得分:0)

您是否检查了此路径:

C:\ Program Files \ Microsoft SQL Server \ MSSQL10.SQLEXPRESS \ MSSQL \ DATA \

它存在吗?

尝试将您的数据库恢复到其他位置(仅用于实验)。