xp_delete_file doesn't work...

I want to delete files from backup activities using xp_delete_files, I created a new maintenance plan to delete *.bak and *.trn files.

Both doesn't work and no error message is generated.

The T-SQL statement being made is:
EXECUTE master.dbo.xp_delete_file 0,N'D:\Backup\iWMC',N'bak',N'2010-05-11T12:48:38'

When I run it in a query window using my own account it fails as well without a message.

I checked
- that the files to be deleted are a result of an backup (the first 0)
- the path is correct no trailing \ (i tried a trailing \ and that doesn't work either)
- file extension doesn't has a . in it (i tried a leading . and that doesn't work either)
- the date contains a T and is of nchar type

The instance is version 9.0.3080 SP2 standard edition on a 64 bit platform.

more ▼

asked May 25, 2010 at 08:09 AM in Default

Rob 2 gravatar image

Rob 2
57 3 3 3

When I try to delete 1 specific file I get: Executed as user: admin-vos. xp_delete_file() returned error 5, 'Access is denied.' [SQLSTATE 42000] (Error 22049). But I can delete the file using the explorer.
May 27, 2010 at 10:33 AM Rob 2
(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

You need to have sysadmin privileges - can you confirm that you are running the maintenance plan with a user with those rights, and that when you try it in a query window you have the right privileges.

more ▼

answered May 25, 2010 at 09:27 AM

Kev Riley gravatar image

Kev Riley ♦♦
53.9k 47 49 76

Thanks for your responce but I checked it and I have sysadmin.

I used: SELECT SSP.name AS [Login Name], SSP.type_desc AS [Login Type], UPPER(SSPS.name) AS [Server Role] FROM sys.server_principals SSP INNER JOIN sys.server_role_members SSRM ON SSP.principal_id=SSRM.member_principal_id INNER JOIN sys.server_principals SSPS ON SSRM.role_principal_id = SSPS.principal_id;

to check my server role, and is is sysadmin.

Sorry for the mess but I can''t change it.
May 27, 2010 at 09:54 AM Rob 2
(comments are locked)
10|1200 characters needed characters left

The joys of using undocumented commands.


However, there is some useful information here: http://sqlblog.com/blogs/andy_leonard/archive/2009/03/11/xp-delete-file.aspx - this link shows a further parameter that your code doesn't have. Perhaps this is the problem?

more ▼

answered May 28, 2010 at 11:42 AM

ThomasRushton gravatar image

ThomasRushton ♦
34.2k 18 20 44

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: May 25, 2010 at 08:09 AM

Seen: 3480 times

Last Updated: May 25, 2010 at 08:57 AM