Deleting files on a Map Network Drive using xp_cmdshell or ...?

  • 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

  • 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.

    _______________________________________________________________________
    For better assistance in answering your questions, click here[/url]

  • 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