XP_CMDSHELL to get files in UNC path

  • I'm trying to get a list of files to delete from a UNC path using a very simple command:

    EXEC master..xp_cmdshell 'DIR \\ServerName\SQL_Backups\'

    If I run it as just a DOS command as the login that is used as the SQL service account from a DOS prompt, it works fine. When I try to run it as a SQL command from within Management Studio or even from an OSQL prompt, it comes back "Access is denied. NULL".

    The login is local admin, SQL sysadmin, is the service account login. The xp_cmdshell is enabled.

    The UNC path is on a Linux based NAS that has permissions setup to allow the user full rights.

    Anyone have any ideas?

    Owner & Principal SQL Server Consultant
    Im Your DBA, Inc.
    https://www.imyourdba.com/

  • The SQL Service account should be domain account with permission to the network shared folder. Or you have add the service account explicitly to access the network shared folder.

  • Yeah, the crazy thing is that it is both domain admin and is explicitly added to the share. 🙁

    Owner & Principal SQL Server Consultant
    Im Your DBA, Inc.
    https://www.imyourdba.com/

  • Have you tried setting up a proxy account for the job in sql agent?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLJocky (2/16/2011)


    Yeah, the crazy thing is that it is both domain admin and is explicitly added to the share. 🙁

    From your original post - it sounded like your service account was a local account. Are you really running SQL Server under a domain admin account?

    Your SQL Server service account should not be a local admin, nor should it be a domain admin. It should only be a domain user with limited rights.

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Yeah, this was a takeover.

    Owner & Principal SQL Server Consultant
    Im Your DBA, Inc.
    https://www.imyourdba.com/

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply