开发者

Getting following error when executing the SP which creates backup and restores it with new name

Could any one help me finding the error in the below 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;

I 开发者_如何学运维am getting the below error

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.


Did you check this path:

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

?

Does it exist?

Try to restore your DB to another place (just for experiment).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜