?
Solved

¿What's wrong with the following Stored Procedure?

Posted on 2011-09-24
2
Medium Priority
?
350 Views
Last Modified: 2012-05-12
When I execute the following SP I got this error:

Msg 22049, Level 15, State 0, Line 0
Error executing extended stored procedure: Invalid Parameter
Processed 1816968 pages for database 'menafn', file 'menafn_Data' on file 1.
Processed 1574 pages for database 'menafn', file 'menafn_Log' on file 1.
BACKUP DATABASE successfully processed 1818542 pages in 661.304 seconds (21.483 MB/sec).

Here is the SP:

DECLARE @backupDate nvarchar(8)
declare @deletedate datetime
declare @statement nvarchar(200)
set @backupDate =cast(day(getdate())as nvarchar)
				+cast (month(getdate())as nvarchar)
				+cast (year(getdate())as nvarchar)
				
 select @deletedate= DATEADD(dd,-7,GETDATE())				
execute xp_delete_file 0, 'Menafn_Sql_backup_weekly', 'bak', @deletedate

set @statement ='BACKUP DATABASE menafn 
		TO DISK = ''C:\Menafn_Sql_backup_weekly\menafn_weekly_'
		+@backupdate+
		'.bak'''
 
execute (@statement)

Open in new window


What Im doing wrong?
0
Comment
Question by:Sindibad_123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
AlokJain0412 earned 2000 total points
ID: 36594779
Hi  Sindibad_123,

Use your statment like that  and
Use it wirh  sa authority

execute master.dbo.xp_delete_file 0,N 'Menafn_Sql_backup_weekly', N'bak', @deletedate
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 36594895
My first question would be why to delete the files. When you will do backup, it will overwrite the existing file. So, why an extra step?

The question to your answer is run the command with the full path. To call the procedure you need to provide the dabatabase name and to delete the file , the location path should be completed

execute master.dbo.xp_delete_file 0,N 'C:\Menafn_Sql_backup_weekly', N'bak', @deletedate
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question