Decrease Font Size
Increase Font Size
   BLOG

How to Delete a File from SQL Server using T-SQL script

Problem: I wanted to delete some files from a certain folder based on the result from a T-SQL in the Job. So, instead of calling another process/service, we try to delete it by using T-SQL. I found a very nice article out there delete file from sql server xp cmdshell ole automation procedures

I execute the following query but it throw me another puzzle

exec sp_configure
go
exec sp_configure 'xp_cmdshell', 1
-- Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.
go
reconfigure
go

Msg 15123, Level 16, State 1, Procedure sp_configure, Line 51
The configuration option 'xp_cmdshell' does not exist, or it may be an advanced option.


Here is the solution I found: Problem with Context Switching feature in SQL 2005

EXEC sp_configure N 'show advanced options', N'1'
RECONFIGURE WITH OVERRIDE

EXEC sp_configure N 'xp_cmdshell', N'1'
RECONFIGURE WITH OVERRIDE

EXEC sp_configure N 'show advanced options', N'0'
RECONFIGURE WITH OVERRIDE

So, if you are looking on how to enable xp_cmdshell, your complete solution is at the top.