xp_dirtree - permission ok but no results returned

  • davidku

    Ten Centuries

    Points: 1256

    Hi Gurus,

    I am using Windows Authentication and Trusted Connection when I connect to SQL Server.

    I have no problem accessing the path and view the files here :

    \\mynetworkpath\folder1\

    However, when I execute it in a store procedure :

    EXEC master.sys.xp_dirtree ' \\mynetworkpath\folder1\', 1, 1

    No results returned.

    To test further, I copied the files to my local drive and it runs perfectly.

    EXEC master.sys.xp_dirtree 'd:\folder1\', 1, 1

    I checked, the file attribute and it is not hidden nor read only.

    Do you have any idea why the file not showing up ?

    Thanks .....

  • SQLRNNR

    SSC Guru

    Points: 281210

    any spaces in the network path?

    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

  • davidku

    Ten Centuries

    Points: 1256

    No spaces and I did not use any special character.

  • SQLRNNR

    SSC Guru

    Points: 281210

    sounds like a permissions issue or possibly a double hop issue

    I have been able to repro under the following circumstances

    two machines not in a domain

    user can access the directories of remote computer (call it computer2) and a specific directory.

    however, i cannot add the user of computer1 to computer2 (since they are somewhat unknown by not being in a workgroup or domain) shares or folder permissions.

    But the user of computer1 can access all directories via xp_dirtree so long as the path is on computer1

    So the next question would be, are the two computers in the same workgroup or domain?

    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

  • davidku

    Ten Centuries

    Points: 1256

    It should be from the same domain but that's something I need to double confirm.

    I managed to fix this issue by using a dos batch file as an alternative solution. Meaning, I run the entire process on DOS rather than inside SSMS.

    1) Move the file from network path to a local drive

    2) Run the store procedure using SQLCMD

    But, it is interesting to know what happen. I tested it in my DEV machine accessing the shared folder on another computer. No problem at all.

    When I moved the script to LIVE server, it doesn't work and not able to pick up any files at all. Initial thought, it could be some server level or database settings that prohibits me from browsing other network directory but I don't recall there are such settings.

    Thanks for your ideas.

  • Maurice Pelchat

    Mr or Mrs. 500

    Points: 537

    You have to take into account, that this is the SQL Server database engine service account that must have the right to access this share.  
    The account under which you are loggued on, cannot supply its own rights to the database engine service. The process that does xp_dirtree is SQL Server service service.  This the one that needs sufficient rights to access the other machine.

    If both machines aren't into the same domain, both startups accounts on both machines must be the same and must have same password.

  • Maurice Pelchat

    Mr or Mrs. 500

    Points: 537

    Maurice Pelchat - Wednesday, March 13, 2019 11:01 PM

    You have to take into account, that this is the SQL Server database engine service account that must have the right to access this share.  
    The account under which you are loggued on, cannot supply its own rights to the database engine service. The process that does xp_dirtree is SQL Server service service.  This the one that needs sufficient rights to access the other machine.

    If both machines aren't into the same domain, both startups accounts on both machines must be the same and must have same password.

    I forgot to add that if you want to change sql service account, it is mandatatory to do it through SQL Server configuration manager. There a numerous other rights that needed to be supply to a SQL Server service, that are necessary to make SQL Server performs all its duties. SQL Server Configuration manager knows them and does them!

Viewing 7 posts - 1 through 7 (of 7 total)

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