How to Delete Files In SQL Server#

You can do this using the extended stored procedure. Problem is you need to configure the database to allow this to run. You need to use sql server "service area" configuration. You also need sys admin rights to run this.
EXEC master..xp_cmdshell 'del C:\file.txt'

To delete files without requiring this access, use the built-in SQL Server Automation and the FileSystemObject, this also needs to be configured in the database to allow this to run. You need to use sql server "service area" configuration

DECLARE @hr int
DECLARE @fileSystem int
EXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @fileSystem OUT
EXEC @hr = sp_OAMethod @fileSystem, 'DeleteFile', NULL, 'C:\pathtofile.txt'
EXEC @hr = sp_OADestroy @fileSystem

Back to SQL Server

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 24-May-2017 15:30 by UnknownAuthor
G’day (anonymous guest) My Prefs
  • View Page Source
  • This clear IPSec security association,
    clear ipsec sa peer X.X.X.X
    

All Pages

Page views: 2323

Private Tomcat

Linux

MySQL

Email

SQL Server

ASP

JSP

C#

Web Mail

Windows Plesk

Linux Plesk

PHP

Gaming

ASP.NET

Persits ASPUpload

Wiki Help

Referring Pages:
...nobody

JSPWiki v2.8.1