Solved

deleting a file with SQL xp_cmdshell

Posted on 2014-09-24
3
166 Views
Last Modified: 2014-09-24
Hello experts,

I am running this one line code on SQL Management Console and it gets hung at 'Executing Query':

exec master..xp_cmdshell 'C:\Test1\Test2\test3.txt'

What is the issue? I login to the SQL Server as the local administrator of that (same) server. Is there something I am missing? Should the folder be shared instead and I use the share name?

Thank you in advance
0
Comment
Question by:bozer
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40340987
>exec master..xp_cmdshell 'C:\Test1\Test2\test3.txt'
this would only "open" the file (on the server, in the sql server login session, so unvisible except in the task manager)

to DELETE the file:


exec master..xp_cmdshell 'del C:\Test1\Test2\test3.txt'
0
 

Author Comment

by:bozer
ID: 40340990
I've requested that this question be deleted for the following reason:

Typo
0
 

Author Closing Comment

by:bozer
ID: 40340991
I just realized that after posting but you were even faster to reply Guy, thanks :)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
space used inside SQL data file- PerfMon counter.. 2 26
MS SQL Delete Query 9 37
sql 2008 how to table join 2 26
Check ALL SP in database make sure there are no errors 17 43
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 …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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