Solved

deleting a file with SQL xp_cmdshell

Posted on 2014-09-24
3
171 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
[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
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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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