March 16, 2009 at 8:23 am
Hello,
I'm having trouble to delete a file on Mapped Network drive using simple query (just to test it ).
If go manually to CMD and write a command it is working with out any problems but If I invoke that same command using xp_cmdshell simply doesn't do trick. Any suggestions?
Thanks for all the help
----Code---
use Master
DECLARE@ResultOutINT
DECLARE @File VARCHAR(500)
DECLARE @CMD VARCHAR(50)
DECLARE @SourcePath VARCHAR(100)
DECLARE @FileName VARCHAR (100)
SELECT @SourcePath = 'W:\temp\'
SELECT @FileName = 'test.txt'
SET @File = @SourcePath+@FileName
SELECT @CMD='del '+@File
EXEC @ResultOut=master..xp_cmdshell @CMD, no_output
March 16, 2009 at 9:33 am
You can't use mapped drives directly, use the UNC path to the shared folder.
Also, make sure your SQL Server is running under a domain account that has the proper permission on the destination server. If you are running SQL under a local account, you could try the trick of mapping the drive, deleting the files and then unmapping the drive. When mapping you can use the user/password to connect.
March 16, 2009 at 9:46 am
UNC path doesn't work but I will try map the drive directly from xp_cmdshell.
Thanks.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply